Commit 4e76cf9f authored by Kevin Whitaker's avatar Kevin Whitaker

Move any code with youtube-dl access(which can be slow) to another thread. Fixes #2.

parent 234e867a
......@@ -4,6 +4,7 @@ project(simplecastengine)
set(QT_MIN_VERSION "5.9.0")
set(KF_MIN_VERSION "5.35.0")
set (CMAKE_CXX_STANDARD 11)
find_package(ECM ${KF_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
......
......@@ -95,6 +95,7 @@ Item {
var loadTrack = service.operationDescription("addURLToPlaylist");
loadTrack.URL = url.text;
service.startOperationCall(loadTrack);
url.text = "";
}
}
}
......
......@@ -19,6 +19,7 @@
#include <QProcess>
#include <QJsonDocument>
#include <QJsonObject>
#include <QtConcurrent/QtConcurrentRun>
MiniMediaPlayer::MiniMediaPlayer(QObject *parent) : QObject(parent)
{
......@@ -40,9 +41,12 @@ bool MiniMediaPlayer::nextTrack()
if(playlist.size() > 1)
{
playlist.pop_front();
m_player->stop();
m_player->setMedia(getStreamUrlFromUrl(playlist.first().second));
emit playlistChanged(getTrackNames());
m_player->pause();
m_player->setPosition(0);
QtConcurrent::run([this]() {
m_player->setMedia(getStreamUrlFromUrl(playlist.first().second));
emit playlistChanged(getTrackNames());
});
return true;
}
else if(playlist.size() == 1)
......@@ -98,25 +102,25 @@ void MiniMediaPlayer::positionChanged(qint64 position)
emit trackPositionChanged(position);
}
bool MiniMediaPlayer::addURLToPlaylist(QUrl mediaUrl)
void MiniMediaPlayer::addURLToPlaylist(QUrl mediaUrl)
{
if(isValidMediaUrl(mediaUrl))
{
bool shouldStartPlaying = false;
if(playlist.size() == 0) shouldStartPlaying = true;
QList<QPair<QString,QUrl>> tracks = getStreamTitlesAndUrlsFromUrl(mediaUrl);
playlist.append(tracks);
emit playlistChanged(getTrackNames());
if(shouldStartPlaying && playlist.size() > 0)
QtConcurrent::run([this,mediaUrl](){
if(isValidMediaUrl(mediaUrl))
{
m_player->setMedia(getStreamUrlFromUrl(playlist.first().second));
}
if(tracks.size() > 0)
{
return true;
bool shouldStartPlaying = false;
if(playlist.size() == 0) shouldStartPlaying = true;
QList<QPair<QString,QUrl>> tracks = getStreamTitlesAndUrlsFromUrl(mediaUrl);
if(tracks.size() > 0)
{
playlist.append(tracks);
emit playlistChanged(getTrackNames());
}
if(shouldStartPlaying && playlist.size() > 0)
{
m_player->setMedia(getStreamUrlFromUrl(playlist.first().second));
}
}
}
return false;
});
}
QUrl MiniMediaPlayer::getStreamUrlFromUrl(QUrl mediaUrl)
......
......@@ -31,7 +31,7 @@ class MiniMediaPlayer : public QObject
public:
MiniMediaPlayer(QObject *parent = 0);
bool addURLToPlaylist(QUrl mediaUrl);
void addURLToPlaylist(QUrl mediaUrl);
QList<QString> getTrackNames();
......
......@@ -43,7 +43,8 @@ public:
{
if(paramaters.contains("URL"))
{
setResult(player->addURLToPlaylist(paramaters["URL"].toUrl()));
player->addURLToPlaylist(paramaters["URL"].toUrl());
emitResult();
}
}
}
......
......@@ -57,7 +57,8 @@ public:
}
else if(message.size() == 3 && message[1] == "addURLToPlaylist")
{
openSocket.write(player->addURLToPlaylist(QUrl(message[2]))?"0":"1");
player->addURLToPlaylist(QUrl(message[2]));
openSocket.write("0");
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment