0.3
This commit is contained in:
parent
fe7ef0115a
commit
0c2b03cecc
4 changed files with 179 additions and 167 deletions
166
main.cpp
166
main.cpp
|
@ -1,171 +1,9 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <vlc/vlc.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QFile>
|
||||
#include <QFrame>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "player.h"
|
||||
|
||||
//using namespace std;
|
||||
|
||||
class Player{
|
||||
public:
|
||||
Player();
|
||||
~Player();
|
||||
|
||||
private:
|
||||
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;
|
||||
};
|
||||
Player::Player(){
|
||||
std::cout << "starte..." << std::endl;
|
||||
|
||||
this->sender_holen();
|
||||
this->sender_laden();
|
||||
this->sender_ausgeben();
|
||||
|
||||
QMainWindow *window;
|
||||
QLabel *label;
|
||||
QPushButton *button;
|
||||
|
||||
window = new QMainWindow;
|
||||
window->resize(1024,576);
|
||||
videoWidget = new QFrame;
|
||||
label = new QLabel("Hello World");
|
||||
button = new QPushButton("Hallo");
|
||||
|
||||
window->setWindowTitle("vlc-vdr");
|
||||
window->setCentralWidget(videoWidget);
|
||||
window->setCentralWidget(label);
|
||||
window->setCentralWidget(button);
|
||||
window->show();
|
||||
//button.show();
|
||||
|
||||
//this->play();
|
||||
//this->play();
|
||||
}
|
||||
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=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;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
/* 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
|
||||
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;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
|
|
144
player.cpp
Normal file
144
player.cpp
Normal file
|
@ -0,0 +1,144 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <vlc/vlc.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QFile>
|
||||
#include <QFrame>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
#include "player.h"
|
||||
|
||||
Player::Player(){
|
||||
std::cout << "starte..." << std::endl;
|
||||
|
||||
this->sender_holen();
|
||||
this->sender_laden();
|
||||
this->sender_ausgeben();
|
||||
|
||||
QPushButton *button;
|
||||
QFrame *videoWidget;
|
||||
|
||||
videoWidget = new QFrame;
|
||||
button = new QPushButton("Hallo");
|
||||
|
||||
videoWidget->show();
|
||||
button->show();
|
||||
|
||||
//this->play();
|
||||
//this->play();
|
||||
}
|
||||
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=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;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
/* 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
|
||||
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;
|
||||
}
|
27
player.h
Normal file
27
player.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QFile>
|
||||
#include <QFrame>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
|
||||
class Player{
|
||||
public:
|
||||
Player();
|
||||
~Player();
|
||||
|
||||
private:
|
||||
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;
|
||||
};
|
||||
|
||||
#endif // PLAYER_H
|
|
@ -4,8 +4,11 @@ QT += core gui
|
|||
greaterThan(QT_MAJOR_VERSION, 4) : QT += widgets
|
||||
|
||||
SOURCES += \
|
||||
main.cpp
|
||||
main.cpp \
|
||||
player.cpp
|
||||
|
||||
INCLUDEPATH += "."
|
||||
win32:LIBS += -L"." -lcurl -llibvlc
|
||||
LIBS += -lcurl -llibvlc
|
||||
DEFINES += CURL_STATICLIB VLC_STATICLIB
|
||||
|
||||
HEADERS += \
|
||||
player.h
|
||||
|
|
Loading…
Add table
Reference in a new issue