#include #include #include #include #include #include #include #include #include #include "player.h" Player::Player(QFrame *video){ this->videoWidget = video; std::cout << "starte..." << std::endl; this->sender_holen(); this->sender_laden(); //this->sender_ausgeben(); // Play init /* Load the VLC engine */ 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){ size_t written = fwrite(ptr, size, nmemb, (FILE *)stream); return written; } int Player::sender_holen(void){ CURL *curl; FILE *file; CURLcode res; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); 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_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; curl_easy_cleanup(curl); } fclose(file); return 0; } int Player::sender_laden(void){ int x=0; this->Sender=1; 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; } } Sender--; //Senderkorrektur } else { std::cout << "Fehler channels.m3u" << std::endl; return 1; } return 0; } int Player::sender_ausgeben(void){ for(int x=1;x<=this->Sender;x++){ std::cout << x << ". " << this->Name[x].toStdString() << "," << this->URL[x].toStdString() << std::endl; } return 0; } int Player::play(QListWidgetItem *item){ if (!item) return 1; std::cout << "Sender: " << item->text().toStdString() << std::endl; int x=1; for(;x<=this->Sender;x++){ if(item->text()==Name[x]){ std::cout << "Name: " << Name[x].toStdString() << " URL: " << URL[x].toStdString() << std::endl; break; } } /* Stop playing */ if(mp) libvlc_media_player_stop (mp); 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()); // 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); return 0; }