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

View file

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

View file

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

View file

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