Compare commits

..

No commits in common. "0.13" and "0.6" have entirely different histories.
0.13 ... 0.6

8 changed files with 263 additions and 420 deletions

42
gui.ui Normal file
View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>941</width>
<height>625</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>290</x>
<y>60</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QListWidget" name="listWidget">
<property name="geometry">
<rect>
<x>540</x>
<y>120</y>
<width>256</width>
<height>192</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -1,15 +1,35 @@
#include <QApplication> #include <iostream>
#include "player_gui.h"
// """ Version 0.11 """ #include <QApplication>
#include <QWidget>
#include <QFrame>
#include <QListWidget>
#include <QHBoxLayout>
#include <QFile>
#include "player.h"
//using namespace std; //using namespace std;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
QApplication app(argc, argv); QApplication app(argc, argv);
player_gui w; QWidget window;
w.show(); //window.resize(200,576);
window.setGeometry(20,50,210,576);
Player player;
QListWidget liste(new QListWidget);
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);
window.show();
return app.exec(); return app.exec();
} }

146
player.cpp Normal file
View file

@ -0,0 +1,146 @@
#include <iostream>
#include <fstream>
#include <string>
#include <curl/curl.h>
#include <vlc/vlc.h>
#include <stdio.h>
#include <stdlib.h>
#include <QFile>
#include <QListWidget>
#include "player.h"
Player::Player(){
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(){
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_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;
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 << 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;
break;
}
}
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 );
#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);
std::cout << "play...stop" << std::endl;
return 0;
}

38
player.h Normal file
View file

@ -0,0 +1,38 @@
#ifndef PLAYER_H
#define PLAYER_H
#include <QObject>
#include <QFile>
#include <QFrame>
#include <QListWidget>
#include <vlc/vlc.h>
class Player : public QObject {
Q_OBJECT
public:
Player();
~Player();
int get_Sender() { return this->Sender; }
QString get_Name(int x) { return this->Name[x]; }
QString get_URL(int x) { return this->URL[x]; }
public slots:
int play(QListWidgetItem *item);
private:
int val;
static write_data(void*, size_t, size_t , void*);
int sender_holen(void);
int sender_laden(void);
int sender_ausgeben(void);
int Sender;
QString Name[10000];
QString URL[10000];
QFrame *videoWidget;
libvlc_instance_t * inst;
libvlc_media_player_t *mp=0;
libvlc_media_t *m;
};
#endif // PLAYER_H

View file

@ -1,226 +0,0 @@
#include "player_gui.h"
#include "ui_player_gui.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <vlc/vlc.h>
#include <stdio.h>
#include <stdlib.h>
#include <QFile>
#include <QFrame>
#include <QInputDialog>
#include <QDir>
#include <QStringList>
#include <QTextStream>
#include <QMessageBox>
#include <QtNetwork>
player_gui::player_gui(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::player_gui){
ui->setupUi(this);
std::cout << "starte..." << std::endl;
ui->statusbar->showMessage("starte...", 0);
this->set_ip();
this->sender_holen();
this->sender_laden();
//this->sender_ausgeben();
this->on_lineEdit_textChanged("");
// Play init
/* Load the VLC engine */
inst = libvlc_new (0, NULL);
}
player_gui::~player_gui(){
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;
delete ui;
}
void player_gui::on_actionBeenden_triggered(){
exit(0);
}
void player_gui::set_ip(void){
QFile file("vlc-vdr.ini");
if(file.open(QIODevice::ReadWrite | QIODevice::Text)){
std::cout << " oeffnen erfolgreich..." << std::endl;
QByteArray line = file.readLine();
QString string = line;
if(string==""){
ip = "127.0.0.1:3000";
QTextStream output(&file);
output << ip;
}else{
ip = string;
}
std::cout << ip.toStdString() << " gesetzt..." << std::endl;
}else{
std::cout << " oeffnen fehlgeschlagen..." << std::endl;
}
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);
bool ok;
QString text = QInputDialog::getText(this, "IP-Adresse", "IP-Adresse(127.0.0.1):Port(3000)",
QLineEdit::Normal, ip, &ok);
if(text!="")
ip = text;
if(file.open(QIODevice::WriteOnly | QIODevice::Text)){
QTextStream output(&file);
output << ip;
file.close();
}
std::cout << text.toStdString() << " gesetzt." << std::endl;
ui->statusbar->showMessage("IP-Adresse setzen... gesetzt.", 0);
this->sender_holen();
this->sender_laden();
this->on_lineEdit_textChanged("");
}
size_t player_gui::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_gui::sender_holen(void){
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;
}
});
return 0;
}
int player_gui::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
file.close();
} else {
std::cout << "Fehler channels.m3u" << std::endl;
return 1;
}
return 0;
}
int player_gui::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;
}
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++){
this->Name_tmp = this->Name[x].toLower();
if(this->Name_tmp.contains(arg1.toLower())){
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){
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;
}
}
ui->statusbar->showMessage(Name[x]+" - "+URL[x], 0);
/* 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 *)ui->videoWidget->winId()); // hwnd
#elif defined(Q_OS_MAC) // Mac
libvlc_media_player_set_nsobject(mp, (void *)ui->videoWidget->winId()); // view
#else //Linux
int windid = ui->videoWidget->winId();
libvlc_media_player_set_xwindow (mp, windid); // xid
#endif
std::cout << "play..." << std::endl;
/* play the media_player */
libvlc_media_player_play (mp);
return 0;
}

View file

@ -1,50 +0,0 @@
#ifndef PLAYER_GUI_H
#define PLAYER_GUI_H
#include <QMainWindow>
#include <QObject>
#include <QFile>
#include <QFrame>
#include <QListWidget>
#include <QtNetwork>
#include <vlc/vlc.h>
namespace Ui {
class player_gui;
}
class player_gui : public QMainWindow{
Q_OBJECT
public:
explicit player_gui(QWidget *parent = 0);
~player_gui();
private slots:
void on_actionBeenden_triggered();
void on_actionIP_Adresse_triggered();
void on_lineEdit_textChanged(const QString &arg1);
int play(QListWidgetItem *item);
void on_listWidget_itemClicked(QListWidgetItem *item);
private:
Ui::player_gui *ui;
void set_ip(void);
static size_t write_data(void*, size_t, size_t , void*);
int sender_holen(void);
int sender_laden(void);
int sender_ausgeben(void);
int Sender;
QString Name[10000];
QString Name_tmp;
QString URL[10000];
QString ip;
QNetworkAccessManager *manager;
QFrame *videoWidget;
libvlc_instance_t * inst;
libvlc_media_player_t *mp=0;
libvlc_media_t *m;
};
#endif // PLAYER_GUI_H

View file

@ -1,116 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>player_gui</class>
<widget class="QMainWindow" name="player_gui">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1160</width>
<height>620</height>
</rect>
</property>
<property name="windowTitle">
<string>vlc-vdr</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="videoWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QListWidget" name="listWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1160</width>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="menuProgramm">
<property name="title">
<string>Programm</string>
</property>
<addaction name="actionBeenden"/>
</widget>
<widget class="QMenu" name="menuEinstellen">
<property name="title">
<string>Einstellen</string>
</property>
<addaction name="actionIP_Adresse"/>
</widget>
<addaction name="menuProgramm"/>
<addaction name="menuEinstellen"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionBeenden">
<property name="text">
<string>Beenden</string>
</property>
</action>
<action name="actionIP_Adresse">
<property name="text">
<string>IP-Adresse</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -1,30 +1,19 @@
QT += \
core \
gui \
widgets \
network
QMAKE_CFLAGS_RELEASE += -Os -momit-leaf-frame-pointer QT += core gui
QMAKE_LFLAGS += -static -static-libgcc greaterThan(QT_MAJOR_VERSION, 4) : QT += widgets
CONFIG += \ SOURCES += \
c++11 \ main.cpp \
static player.cpp
DEFINES += \ LIBS += -lcurl -llibvlc
VLC_STATICLIB \ DEFINES += CURL_STATICLIB VLC_STATICLIB
QT_STATIC_BUILD
LIBS += \ HEADERS += \
-lvlc.dll player.h
SOURCES += \ DISTFILES +=
main.cpp \
player_gui.cpp
HEADERS += \ FORMS += \
player_gui.h gui.ui
FORMS += \
player_gui.ui