2025-02-15 07:30:59 +01:00
|
|
|
#include <iostream>
|
2025-02-15 07:31:32 +01:00
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
2025-02-15 07:30:59 +01:00
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
#include <vlc/vlc.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QMainWindow>
|
2025-02-15 07:31:32 +01:00
|
|
|
#include <QFile>
|
2025-02-15 07:30:59 +01:00
|
|
|
#include <QFrame>
|
|
|
|
#include <QLabel>
|
2025-02-15 07:31:32 +01:00
|
|
|
#include <QPushButton>
|
2025-02-15 07:30:59 +01:00
|
|
|
|
2025-02-15 07:31:32 +01:00
|
|
|
//using namespace std;
|
2025-02-15 07:30:59 +01:00
|
|
|
|
|
|
|
class Player{
|
|
|
|
public:
|
|
|
|
Player();
|
|
|
|
~Player();
|
|
|
|
|
|
|
|
private:
|
2025-02-15 07:31:32 +01:00
|
|
|
static write_data(void*, size_t, size_t , void*);
|
|
|
|
int sender_holen(void);
|
|
|
|
int sender_laden(void);
|
|
|
|
int Sender;
|
|
|
|
QString Name[10000];
|
|
|
|
QString URL[10000];
|
|
|
|
int sender_ausgeben(void);
|
|
|
|
int play(void);
|
|
|
|
QFrame *videoWidget;
|
2025-02-15 07:30:59 +01:00
|
|
|
};
|
|
|
|
Player::Player(){
|
2025-02-15 07:31:32 +01:00
|
|
|
std::cout << "starte..." << std::endl;
|
|
|
|
|
2025-02-15 07:30:59 +01:00
|
|
|
this->sender_holen();
|
2025-02-15 07:31:32 +01:00
|
|
|
this->sender_laden();
|
|
|
|
this->sender_ausgeben();
|
|
|
|
|
|
|
|
QMainWindow *window;
|
|
|
|
QLabel *label;
|
|
|
|
QPushButton *button;
|
2025-02-15 07:30:59 +01:00
|
|
|
|
|
|
|
window = new QMainWindow;
|
2025-02-15 07:31:32 +01:00
|
|
|
window->resize(1024,576);
|
2025-02-15 07:30:59 +01:00
|
|
|
videoWidget = new QFrame;
|
|
|
|
label = new QLabel("Hello World");
|
2025-02-15 07:31:32 +01:00
|
|
|
button = new QPushButton("Hallo");
|
|
|
|
|
2025-02-15 07:30:59 +01:00
|
|
|
window->setWindowTitle("vlc-vdr");
|
|
|
|
window->setCentralWidget(videoWidget);
|
|
|
|
window->setCentralWidget(label);
|
2025-02-15 07:31:32 +01:00
|
|
|
window->setCentralWidget(button);
|
2025-02-15 07:30:59 +01:00
|
|
|
window->show();
|
2025-02-15 07:31:32 +01:00
|
|
|
//button.show();
|
2025-02-15 07:30:59 +01:00
|
|
|
|
2025-02-15 07:31:32 +01:00
|
|
|
//this->play();
|
|
|
|
//this->play();
|
2025-02-15 07:30:59 +01:00
|
|
|
}
|
|
|
|
Player::~Player(){
|
2025-02-15 07:31:32 +01:00
|
|
|
std::cout << "beende..." << std::endl;
|
|
|
|
}
|
|
|
|
Player::write_data(void *ptr, size_t size, size_t nmemb, void *stream){
|
|
|
|
size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
|
|
|
|
return written;
|
2025-02-15 07:30:59 +01:00
|
|
|
}
|
2025-02-15 07:31:32 +01:00
|
|
|
int Player::sender_holen(void){
|
|
|
|
CURL *curl;
|
|
|
|
FILE *file;
|
|
|
|
CURLcode res;
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
2025-02-15 07:30:59 +01:00
|
|
|
curl = curl_easy_init();
|
2025-02-15 07:31:32 +01:00
|
|
|
if(curl){
|
2025-02-15 07:30:59 +01:00
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.101.9:3000/channels.m3u");
|
2025-02-15 07:31:32 +01:00
|
|
|
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);
|
2025-02-15 07:30:59 +01:00
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
if(res != CURLE_OK)
|
2025-02-15 07:31:32 +01:00
|
|
|
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
|
|
|
else
|
|
|
|
std::cout << "Sender holen und in channels.m3u speichern..." << std::endl;
|
2025-02-15 07:30:59 +01:00
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
}
|
2025-02-15 07:31:32 +01:00
|
|
|
fclose(file);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int Player::sender_laden(void){
|
|
|
|
int x=0;
|
|
|
|
this->Sender=0;
|
|
|
|
QFile file("channels.m3u");
|
|
|
|
if(file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
|
|
|
while (!file.atEnd()){
|
|
|
|
QByteArray line = file.readLine();
|
|
|
|
if(line.toStdString()=="#EXTM3U\n") // erste Zeile überspringen
|
|
|
|
continue;
|
|
|
|
if(line.toStdString()=="\n") // lezte Zeile überspringen
|
|
|
|
break;
|
|
|
|
QString string = line;
|
|
|
|
string.replace(QString("#EXTINF:-1,"), QString(""));
|
|
|
|
string.replace(QString("\n"), QString("")); // Zeilenede entfernen
|
|
|
|
if(++x%2){
|
|
|
|
std::cout << this->Sender << " Name: " << string.toStdString() << std::endl;
|
|
|
|
this->Name[this->Sender]=string;
|
|
|
|
} else {
|
|
|
|
std::cout << this->Sender <<" Url: " << string.toStdString() << std::endl;
|
|
|
|
this->URL[this->Sender++]=string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
std::cout << "Fehler channels.m3u" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2025-02-15 07:30:59 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2025-02-15 07:31:32 +01:00
|
|
|
int Player::sender_ausgeben(void){
|
|
|
|
for(int x=0;x<this->Sender;x++){
|
|
|
|
std::cout << x << ". " << this->Name[x].toStdString() << "," << this->URL[x].toStdString() << std::endl;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int Player::play(void){
|
|
|
|
libvlc_instance_t * inst;
|
|
|
|
libvlc_media_player_t *mp;
|
|
|
|
libvlc_media_t *m;
|
|
|
|
|
|
|
|
std::cout << "play..." << std::endl;
|
2025-02-15 07:30:59 +01:00
|
|
|
/* Load the VLC engine */
|
|
|
|
inst = libvlc_new (0, NULL);
|
|
|
|
|
|
|
|
/* Create a new item */
|
|
|
|
m = libvlc_media_new_location (inst, "http://192.168.101.9:3000/S19.2E-133-33-51");
|
|
|
|
|
|
|
|
/* 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
|
2025-02-15 07:31:32 +01:00
|
|
|
libvlc_media_player_set_hwnd(mp, (void *)videoWidget->winId());
|
2025-02-15 07:30:59 +01:00
|
|
|
#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 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* 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);
|
2025-02-15 07:31:32 +01:00
|
|
|
std::cout << "play...stop" << std::endl;
|
2025-02-15 07:30:59 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
QApplication app(argc, argv);
|
2025-02-15 07:31:32 +01:00
|
|
|
Player player;
|
2025-02-15 07:30:59 +01:00
|
|
|
return app.exec();
|
|
|
|
}
|