2025-02-15 07:42:24 +01:00
|
|
|
#include "player_gui.h"
|
|
|
|
#include "ui_player_gui.h"
|
|
|
|
|
2025-02-15 07:32:07 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
2025-02-15 07:42:24 +01:00
|
|
|
#include <cstdlib>
|
2025-02-15 07:32:07 +01:00
|
|
|
|
|
|
|
#include <vlc/vlc.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <QFile>
|
2025-02-15 07:38:45 +01:00
|
|
|
#include <QFrame>
|
2025-02-15 07:41:16 +01:00
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QMessageBox>
|
2025-02-15 07:43:27 +01:00
|
|
|
#include <QtNetwork>
|
2025-02-15 07:32:07 +01:00
|
|
|
|
2025-02-15 07:42:24 +01:00
|
|
|
player_gui::player_gui(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
|
|
|
ui(new Ui::player_gui){
|
|
|
|
|
|
|
|
ui->setupUi(this);
|
2025-02-15 07:32:07 +01:00
|
|
|
|
|
|
|
std::cout << "starte..." << std::endl;
|
2025-02-15 07:42:24 +01:00
|
|
|
ui->statusbar->showMessage("starte...", 0);
|
2025-02-15 07:32:07 +01:00
|
|
|
|
2025-02-15 07:42:24 +01:00
|
|
|
this->set_ip();
|
2025-02-15 07:32:07 +01:00
|
|
|
this->sender_holen();
|
|
|
|
this->sender_laden();
|
2025-02-15 07:33:46 +01:00
|
|
|
//this->sender_ausgeben();
|
2025-02-15 07:42:24 +01:00
|
|
|
this->on_lineEdit_textChanged("");
|
2025-02-15 07:32:07 +01:00
|
|
|
|
2025-02-15 07:34:15 +01:00
|
|
|
// Play init
|
|
|
|
/* Load the VLC engine */
|
|
|
|
inst = libvlc_new (0, NULL);
|
2025-02-15 07:32:07 +01:00
|
|
|
}
|
2025-02-15 07:42:24 +01:00
|
|
|
player_gui::~player_gui(){
|
2025-02-15 07:38:45 +01:00
|
|
|
if(mp){
|
|
|
|
/* Stop playing */
|
|
|
|
libvlc_media_player_stop (mp);
|
|
|
|
/* Free the media_player */
|
|
|
|
libvlc_media_player_release (mp);
|
|
|
|
libvlc_release (inst);
|
|
|
|
}
|
2025-02-15 07:32:07 +01:00
|
|
|
std::cout << "beende..." << std::endl;
|
2025-02-15 07:42:24 +01:00
|
|
|
|
|
|
|
delete ui;
|
2025-02-15 07:32:07 +01:00
|
|
|
}
|
2025-02-15 07:42:24 +01:00
|
|
|
void player_gui::on_actionBeenden_triggered(){
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
void player_gui::set_ip(void){
|
2025-02-15 07:41:16 +01:00
|
|
|
QFile file("vlc-vdr.ini");
|
2025-02-15 07:42:24 +01:00
|
|
|
if(file.open(QIODevice::ReadWrite | QIODevice::Text)){
|
2025-02-15 07:41:16 +01:00
|
|
|
std::cout << " oeffnen erfolgreich..." << std::endl;
|
|
|
|
QByteArray line = file.readLine();
|
|
|
|
QString string = line;
|
|
|
|
if(string==""){
|
|
|
|
ip = "127.0.0.1:3000";
|
2025-02-15 07:42:24 +01:00
|
|
|
QTextStream output(&file);
|
|
|
|
output << ip;
|
2025-02-15 07:41:16 +01:00
|
|
|
}else{
|
|
|
|
ip = string;
|
|
|
|
}
|
|
|
|
std::cout << ip.toStdString() << " gesetzt..." << std::endl;
|
|
|
|
}else{
|
|
|
|
std::cout << " oeffnen fehlgeschlagen..." << std::endl;
|
|
|
|
}
|
2025-02-15 07:42:24 +01:00
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
void player_gui::on_actionIP_Adresse_triggered() {
|
|
|
|
this->set_ip();
|
|
|
|
QFile file("vlc-vdr.ini");
|
|
|
|
std::cout << "IP-Adresse setzen..." << std::endl;
|
|
|
|
ui->statusbar->showMessage("IP-Adresse setzen...", 0);
|
2025-02-15 07:41:16 +01:00
|
|
|
bool ok;
|
2025-02-15 07:42:24 +01:00
|
|
|
QString text = QInputDialog::getText(this, "IP-Adresse", "IP-Adresse(127.0.0.1):Port(3000)",
|
2025-02-15 07:41:16 +01:00
|
|
|
QLineEdit::Normal, ip, &ok);
|
2025-02-15 07:42:24 +01:00
|
|
|
if(text!="")
|
|
|
|
ip = text;
|
2025-02-15 07:41:16 +01:00
|
|
|
if(file.open(QIODevice::WriteOnly | QIODevice::Text)){
|
|
|
|
QTextStream output(&file);
|
|
|
|
output << ip;
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
std::cout << text.toStdString() << " gesetzt." << std::endl;
|
2025-02-15 07:42:24 +01:00
|
|
|
ui->statusbar->showMessage("IP-Adresse setzen... gesetzt.", 0);
|
|
|
|
this->sender_holen();
|
|
|
|
this->sender_laden();
|
|
|
|
this->on_lineEdit_textChanged("");
|
2025-02-15 07:41:16 +01:00
|
|
|
}
|
2025-02-15 07:42:24 +01:00
|
|
|
size_t player_gui::write_data(void *ptr, size_t size, size_t nmemb, void *stream){
|
2025-02-15 07:32:07 +01:00
|
|
|
size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
|
|
|
|
return written;
|
|
|
|
}
|
2025-02-15 07:42:24 +01:00
|
|
|
int player_gui::sender_holen(void){
|
2025-02-15 07:43:27 +01:00
|
|
|
|
|
|
|
manager = new QNetworkAccessManager();
|
|
|
|
|
|
|
|
QString url = "http://" + ip + "/channels.m3u";
|
|
|
|
QNetworkRequest request(url);
|
|
|
|
QNetworkReply *reply = manager->get(request);
|
|
|
|
|
|
|
|
connect(reply, &QNetworkReply::finished, [=]() {
|
|
|
|
if(reply->error() == QNetworkReply::NoError)
|
|
|
|
{
|
|
|
|
QByteArray response = reply->readAll();
|
|
|
|
std::string Daten = response.toStdString();
|
|
|
|
std::cout << Daten << std::endl;
|
|
|
|
// do something with the data...
|
|
|
|
FILE *file = fopen("channels.m3u", "wb");
|
|
|
|
if (file!=NULL)
|
|
|
|
{
|
|
|
|
std::fputs(response,file);
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
else // handle error
|
|
|
|
{
|
|
|
|
ui->statusbar->showMessage(reply->errorString().toUtf8().constData());
|
|
|
|
std::cout << reply->errorString().toUtf8().constData() << std::endl;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-02-15 07:32:07 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2025-02-15 07:42:24 +01:00
|
|
|
int player_gui::sender_laden(void){
|
2025-02-15 07:32:07 +01:00
|
|
|
int x=0;
|
2025-02-15 07:33:46 +01:00
|
|
|
this->Sender=1;
|
2025-02-15 07:32:07 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2025-02-15 07:33:46 +01:00
|
|
|
Sender--; //Senderkorrektur
|
2025-02-15 07:41:16 +01:00
|
|
|
file.close();
|
2025-02-15 07:32:07 +01:00
|
|
|
} else {
|
|
|
|
std::cout << "Fehler channels.m3u" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2025-02-15 07:42:24 +01:00
|
|
|
int player_gui::sender_ausgeben(void){
|
2025-02-15 07:33:46 +01:00
|
|
|
for(int x=1;x<=this->Sender;x++){
|
2025-02-15 07:32:07 +01:00
|
|
|
std::cout << x << ". " << this->Name[x].toStdString() << "," << this->URL[x].toStdString() << std::endl;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2025-02-15 07:42:24 +01:00
|
|
|
void player_gui::on_lineEdit_textChanged(const QString &arg1){
|
|
|
|
std::cout << "suchen" << std::endl;
|
|
|
|
ui->listWidget->clear();
|
|
|
|
for(int x=1;x<=this->Sender;x++){
|
|
|
|
if(this->Name[x].contains(arg1)){
|
|
|
|
ui->listWidget->addItem(this->Name[x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void player_gui::on_listWidget_itemClicked(QListWidgetItem *item)
|
|
|
|
{
|
|
|
|
std::cout << item->text().toStdString() << std::endl;
|
|
|
|
this->play(item);
|
|
|
|
}
|
|
|
|
int player_gui::play(QListWidgetItem *item){
|
2025-02-15 07:34:15 +01:00
|
|
|
|
|
|
|
if (!item)
|
|
|
|
return 1;
|
2025-02-15 07:38:45 +01:00
|
|
|
std::cout << "Sender: " << item->text().toStdString() << std::endl;
|
2025-02-15 07:34:15 +01:00
|
|
|
|
|
|
|
int x=1;
|
|
|
|
|
|
|
|
for(;x<=this->Sender;x++){
|
|
|
|
if(item->text()==Name[x]){
|
2025-02-15 07:38:45 +01:00
|
|
|
std::cout << "Name: " << Name[x].toStdString() << " URL: " << URL[x].toStdString() << std::endl;
|
2025-02-15 07:34:15 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2025-02-15 07:42:24 +01:00
|
|
|
ui->statusbar->showMessage(Name[x]+" - "+URL[x], 0);
|
2025-02-15 07:38:45 +01:00
|
|
|
/* Stop playing */
|
2025-02-15 07:34:15 +01:00
|
|
|
if(mp)
|
|
|
|
libvlc_media_player_stop (mp);
|
2025-02-15 07:32:07 +01:00
|
|
|
|
2025-02-15 07:34:15 +01:00
|
|
|
QByteArray bla = URL[x].toLatin1();
|
|
|
|
const char *url = bla.data();
|
2025-02-15 07:32:07 +01:00
|
|
|
|
|
|
|
/* Create a new item */
|
2025-02-15 07:34:15 +01:00
|
|
|
m = libvlc_media_new_location (inst, url);
|
2025-02-15 07:32:07 +01:00
|
|
|
/* 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);
|
|
|
|
|
2025-02-15 07:38:45 +01:00
|
|
|
#if defined(Q_OS_WIN) // Windows
|
2025-02-15 07:42:24 +01:00
|
|
|
libvlc_media_player_set_hwnd(mp, (void *)ui->videoWidget->winId()); // hwnd
|
2025-02-15 07:38:45 +01:00
|
|
|
#elif defined(Q_OS_MAC) // Mac
|
2025-02-15 07:42:24 +01:00
|
|
|
libvlc_media_player_set_nsobject(mp, (void *)ui->videoWidget->winId()); // view
|
2025-02-15 07:38:45 +01:00
|
|
|
#else //Linux
|
2025-02-15 07:42:24 +01:00
|
|
|
int windid = ui->videoWidget->winId();
|
2025-02-15 07:40:16 +01:00
|
|
|
libvlc_media_player_set_xwindow (mp, windid); // xid
|
2025-02-15 07:32:07 +01:00
|
|
|
#endif
|
|
|
|
|
2025-02-15 07:38:45 +01:00
|
|
|
std::cout << "play..." << std::endl;
|
2025-02-15 07:32:07 +01:00
|
|
|
/* play the media_player */
|
|
|
|
libvlc_media_player_play (mp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|