This commit is contained in:
Thomas resiX 2025-02-15 07:38:45 +01:00
parent 53831d0ec5
commit b1916d525c
4 changed files with 34 additions and 37 deletions

View file

@ -3,12 +3,13 @@
#include <QApplication>
#include <QWidget>
#include <QFrame>
#include <QListWidget>
#include <QHBoxLayout>
#include <QFile>
#include "player.h"
// """ Version 0.7 """
//using namespace std;
@ -17,18 +18,22 @@ int main(int argc, char* argv[]) {
QWidget window;
//window.resize(200,576);
window.setGeometry(20,50,210,576);
window.setGeometry(20,50,1234,576);
Player player;
QFrame videoWidget(&window);
videoWidget.resize(1024, 576);
Player player(&videoWidget);
QListWidget liste(new QListWidget);
QListWidget liste(&window);
liste.setGeometry(1024,0,210,576);
for(int x=1;x<=player.get_Sender();x++){
liste.addItem(player.get_Name(x));
}
QObject::connect(&liste, SIGNAL(itemClicked(QListWidgetItem*)), &player, SLOT(play(QListWidgetItem*)));
QHBoxLayout layout(&window);
layout.addWidget(&liste);
//QHBoxLayout layout(&window);
//layout.addWidget(&videoWidget);
//layout.addWidget(&liste);
window.show();
return app.exec();

View file

@ -9,11 +9,12 @@
#include <stdlib.h>
#include <QFile>
#include <QListWidget>
#include <QFrame>
#include "player.h"
Player::Player(){
Player::Player(QFrame *video){
this->videoWidget = video;
std::cout << "starte..." << std::endl;
this->sender_holen();
@ -25,6 +26,13 @@ Player::Player(){
inst = libvlc_new (0, NULL);
}
Player::~Player(){
if(mp){
/* Stop playing */
libvlc_media_player_stop (mp);
/* Free the media_player */
libvlc_media_player_release (mp);
libvlc_release (inst);
}
std::cout << "beende..." << std::endl;
}
Player::write_data(void *ptr, size_t size, size_t nmemb, void *stream){
@ -40,15 +48,14 @@ int Player::sender_holen(void){
if(curl){
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.101.9:3000/channels.m3u");
file = fopen("channels.m3u", "wb");
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
//curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, this->write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
else
std::cout << "Sender holen und in channels.m3u speichern..." << std::endl;
std::cout << "Sender holen und in channels.m3u speichern..." << std::endl;
curl_easy_cleanup(curl);
}
fclose(file);
@ -93,54 +100,42 @@ int Player::play(QListWidgetItem *item){
if (!item)
return 1;
std::cout << item->text().toStdString() << std::endl;
std::cout << "Sender: " << item->text().toStdString() << std::endl;
int x=1;
for(;x<=this->Sender;x++){
if(item->text()==Name[x]){
std::cout << Name[x].toStdString() << " " << URL[x].toStdString() << std::endl;
std::cout << "Name: " << Name[x].toStdString() << " URL: " << URL[x].toStdString() << std::endl;
break;
}
}
/* Stop playing */
if(mp)
libvlc_media_player_stop (mp);
std::cout << "play..." << std::endl;
QByteArray bla = URL[x].toLatin1();
const char *url = bla.data();
/* Create a new item */
m = libvlc_media_new_location (inst, url);
/* Create a media player playing environement */
mp = libvlc_media_player_new_from_media (m);
/* No need to keep the media now */
libvlc_media_release (m);
#if defined(Q_OS_WIN) // Windows
// libvlc_media_player_set_hwnd(mp, (void *)videoWidget->winId());
#elif defined(Q_OS_MAC) // Mac
libvlc_media_player_set_nsobject(mp, (void *)videoWidget->winId());
#else //Linux
int windid = _videoWidget->winId();
libvlc_media_player_set_xwindow (mp, windid );
#if defined(Q_OS_WIN) // Windows
libvlc_media_player_set_hwnd(mp, (void *)videoWidget->winId()); // hwnd
#elif defined(Q_OS_MAC) // Mac
libvlc_media_player_set_nsobject(mp, (void *)videoWidget->winId()); // view
#else //Linux
libvlc_media_player_set_xwindow (mp, (void *)videoWidget->winId()); // xid
#endif
std::cout << "play..." << std::endl;
/* play the media_player */
libvlc_media_player_play (mp);
Sleep(10000); /* Let it play a bit */
/* Stop playing */
//libvlc_media_player_stop (mp);
/* Free the media_player */
//libvlc_media_player_release (mp);
//libvlc_release (inst);
std::cout << "play...stop" << std::endl;
return 0;
}

View file

@ -10,7 +10,7 @@
class Player : public QObject {
Q_OBJECT
public:
Player();
Player(QFrame*);
~Player();
int get_Sender() { return this->Sender; }
QString get_Name(int x) { return this->Name[x]; }

View file

@ -13,7 +13,4 @@ DEFINES += CURL_STATICLIB VLC_STATICLIB
HEADERS += \
player.h
DISTFILES +=
FORMS += \
gui.ui