summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchriszero <zerov83@gmail.com>2015-10-11 19:07:10 +0200
committerchriszero <zerov83@gmail.com>2015-10-11 19:07:10 +0200
commit75e178bcc0105e5f618e913d53cca91450a6e8bd (patch)
treeb0eef5ad0534c58e2e42d11a256b3d5e5542f1c6
parent0be6c14499cbc7351578198e8f15b3e1bf1b1335 (diff)
downloadvdr-plugin-plex-75e178bcc0105e5f618e913d53cca91450a6e8bd.tar.gz
vdr-plugin-plex-75e178bcc0105e5f618e913d53cca91450a6e8bd.tar.bz2
Better support for vdr-plugin-mpv.
-rw-r--r--PlexHTTPRequestHandler.cpp33
-rw-r--r--SubscriptionManager.cpp46
-rw-r--r--SubscriptionManager.h1
-rw-r--r--mpvWrapper.cpp10
-rw-r--r--mpvWrapper.h12
-rw-r--r--plex.cpp34
-rw-r--r--plex.h4
-rw-r--r--services.h7
8 files changed, 133 insertions, 14 deletions
diff --git a/PlexHTTPRequestHandler.cpp b/PlexHTTPRequestHandler.cpp
index 4fade01..8cf8cef 100644
--- a/PlexHTTPRequestHandler.cpp
+++ b/PlexHTTPRequestHandler.cpp
@@ -6,6 +6,7 @@
#include <Poco/SharedPtr.h>
#include "hlsPlayerControl.h"
+#include "services.h"
namespace plexclient
{
@@ -215,6 +216,14 @@ void PlayerRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request,
if(control) {
isyslog("[plex] Seeking to %d", offset);
control->SeekTo(offset);
+ } else if(cMyPlugin::PlayingFile) {
+ cPlugin* mpvPlugin = cPluginManager::GetPlugin("mpv");
+ if(mpvPlugin) {
+ Mpv_Seek seekData;
+ seekData.SeekAbsolute = offset;
+ seekData.SeekRelative = 0;
+ mpvPlugin->Service(MPV_SEEK, &seekData);
+ }
}
}
} else if(request.getURI().find("/playback/playMedia") != std::string::npos) {
@@ -233,6 +242,10 @@ void PlayerRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request,
// MUSS im Maintread des Plugins/VDR gestartet werden
if(query.find("offset") != query.end()) {
Cont->m_vVideos[0].m_iMyPlayOffset = atoi(query["offset"].c_str()) / 1000;
+ if(Cont->m_vVideos[0].m_iMyPlayOffset == 0) {
+ Cont->m_vVideos[0].m_iMyPlayOffset = -1;
+ }
+
}
ActionManager::GetInstance().AddAction(Cont->m_vVideos[0]);
@@ -247,14 +260,30 @@ void PlayerRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request,
cHlsPlayerControl* control = dynamic_cast<cHlsPlayerControl*>(cControl::Control(true));
if(control) {
control->JumpRelative(30);
+ } else if(cMyPlugin::PlayingFile) {
+ cPlugin* mpvPlugin = cPluginManager::GetPlugin("mpv");
+ if(mpvPlugin) {
+ Mpv_Seek seekData;
+ seekData.SeekAbsolute = 0;
+ seekData.SeekRelative = 30;
+ mpvPlugin->Service(MPV_SEEK, &seekData);
+ }
} else
cRemote::Put(kFastFwd);
} else if(request.getURI().find("/playback/stepBack") != std::string::npos) {
cHlsPlayerControl* control = dynamic_cast<cHlsPlayerControl*>(cControl::Control(true));
if(control) {
control->JumpRelative(-15);
- }
- cRemote::Put(kFastRew);
+ }else if(cMyPlugin::PlayingFile) {
+ cPlugin* mpvPlugin = cPluginManager::GetPlugin("mpv");
+ if(mpvPlugin) {
+ Mpv_Seek seekData;
+ seekData.SeekAbsolute = 0;
+ seekData.SeekRelative = -15;
+ mpvPlugin->Service(MPV_SEEK, &seekData);
+ }
+ } else
+ cRemote::Put(kFastRew);
} else if(request.getURI().find("/playback/skipNext") != std::string::npos) {
cRemote::Put(kFastFwd);
} else if(request.getURI().find("/playback/skipPrevious") != std::string::npos) {
diff --git a/SubscriptionManager.cpp b/SubscriptionManager.cpp
index ce82358..aa10077 100644
--- a/SubscriptionManager.cpp
+++ b/SubscriptionManager.cpp
@@ -12,6 +12,7 @@
#include "Plexservice.h"
#include "plexgdm.h"
#include "PlexHelper.h"
+#include "plex.h"
namespace plexclient
{
@@ -32,6 +33,42 @@ void SubscriptionManager::Notify()
subs.SendUpdate(GetMsg(subs.m_iCommandId), false);
}
NotifyServer();
+ ReportProgress();
+}
+
+void SubscriptionManager::ReportProgress()
+{
+ if(!m_pStatus->pVideo) {
+ return;
+ }
+
+ try {
+ int current, total, speed;
+ bool play, forward;
+ if(!m_pStatus->PlayerStopped && m_pStatus->pControl) {
+ m_pStatus->pControl->GetIndex(current, total);
+ current = current / m_pStatus->pControl->FramesPerSecond() * 1000;
+ total = total / m_pStatus->pControl->FramesPerSecond() * 1000;
+ m_pStatus->pControl->GetReplayMode(play, forward, speed);
+ } else {
+ return;
+ }
+
+ m_pStatus->pControl->GetReplayMode(play, forward, speed);
+
+ std::string state = "playing";
+ if (m_pStatus->PlayerStopped) state = "stopped";
+ else if(!play) state = "paused";
+
+ Poco::Net::HTTPClientSession session(m_pStatus->pVideo->m_pServer->GetIpAdress(), m_pStatus->pVideo->m_pServer->GetPort());
+ std::string uri = "/:/progress?key=" + std::string(itoa(m_pStatus->pVideo->m_iRatingKey)) + "&identifier=com.plexapp.plugins.library&time=" + std::string(itoa(current)) + "&state=" + state;
+ Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, uri);
+ session.sendRequest(req);
+
+ Poco::Net::HTTPResponse resp;
+ session.receiveResponse(resp);
+
+ } catch (Poco::Exception&) {}
}
void SubscriptionManager::NotifyServer()
@@ -249,15 +286,22 @@ void cSubscriberStatus::Replaying(const cControl* DvbPlayerControl, const char*
{
//dsyslog("[plex]: '%s'", __FUNCTION__);
PlayerStopped = !On;
+
+ if(PlayerStopped) {
+ cMyPlugin::PlayingFile = false;
+ }
+
pControl = const_cast<cControl*>(DvbPlayerControl);
cHlsPlayerControl* hlsControl = dynamic_cast<cHlsPlayerControl*>(pControl);
if(hlsControl) {
pVideo = &hlsControl->m_Video;
+ } else if(cMyPlugin::PlayingFile) {
+ pVideo = &cMyPlugin::CurrentVideo;
} else {
pVideo = NULL;
pControl = NULL;
}
-
+
SubscriptionManager::GetInstance().Notify();
}
diff --git a/SubscriptionManager.h b/SubscriptionManager.h
index fc96448..3da053c 100644
--- a/SubscriptionManager.h
+++ b/SubscriptionManager.h
@@ -78,6 +78,7 @@ private:
cSubscriberStatus* m_pStatus;
bool m_bStoppedSent;
+ void ReportProgress();
void NotifyServer();
void Cleanup();
std::string GetTimelineXml();
diff --git a/mpvWrapper.cpp b/mpvWrapper.cpp
new file mode 100644
index 0000000..4986705
--- /dev/null
+++ b/mpvWrapper.cpp
@@ -0,0 +1,10 @@
+#include "mpvWrapper.h"
+
+cMpvWrapper::cMpvWrapper()
+{
+}
+
+cMpvWrapper::~cMpvWrapper()
+{
+}
+
diff --git a/mpvWrapper.h b/mpvWrapper.h
new file mode 100644
index 0000000..890a27f
--- /dev/null
+++ b/mpvWrapper.h
@@ -0,0 +1,12 @@
+#ifndef CMPVWRAPPER_H
+#define CMPVWRAPPER_H
+
+class cMpvWrapper
+{
+public:
+ cMpvWrapper();
+ ~cMpvWrapper();
+
+};
+
+#endif // CMPVWRAPPER_H
diff --git a/plex.cpp b/plex.cpp
index f0042f3..801f497 100644
--- a/plex.cpp
+++ b/plex.cpp
@@ -15,6 +15,9 @@
volatile bool cMyPlugin::CalledFromCode = false;
bool cMyPlugin::bSkindesigner = false;
+plexclient::Video cMyPlugin::CurrentVideo;
+bool cMyPlugin::PlayingFile = false;
+
/**
** Initialize any member variables here.
**
@@ -79,7 +82,7 @@ bool cMyPlugin::Start(void)
reg.SetViewElement(viDetailView, vedHeader, "header");
reg.SetViewElement(viDetailView, vedFooter, "footer");
*/
-
+
//reg.SetMenu(meRoot, "streamselect.xml");
if (skindesignerapi::SkindesignerAPI::RegisterPlugin(&reg)) {
m_pSdCheck = new cPlexSdOsd();
@@ -169,18 +172,36 @@ bool cMyPlugin::SetupParse(const char *name, const char *value)
*/
void cMyPlugin::PlayFile(plexclient::Video Vid)
{
+ if(Vid.m_iMyPlayOffset == 0 && Vid.m_lViewoffset > 0 ) {
+ cString message = cString::sprintf(tr("To start from %ld minutes, press Ok."), Vid.m_lViewoffset / 60000);
+ eKeys response = Skins.Message(eMessageType::mtInfo, message, 5);
+ if(response == kOk) {
+ Vid.m_iMyPlayOffset = Vid.m_lViewoffset/1000;
+ }
+ }
+
cPlugin* mpvPlugin = cPluginManager::GetPlugin("mpv");
if(Config::GetInstance().UseMpv && mpvPlugin) {
+ CurrentVideo = Vid;
+ cMyPlugin::PlayingFile = true;
+
Mpv_PlayFile req;
Mpv_SetTitle reqTitle;
char* file = (char*)(Vid.m_pServer->GetUri() + Vid.m_Media.m_sPartKey).c_str();
-
+
req.Filename = file;
mpvPlugin->Service(MPV_PLAY_FILE, &req);
-
+
reqTitle.Title = (char*)Vid.GetTitle().c_str();
mpvPlugin->Service(MPV_SET_TITLE, &reqTitle);
+
+ // Set "StartAt" for mpv player
+ Mpv_Seek seekData;
+ seekData.SeekAbsolute = Vid.m_iMyPlayOffset;
+ seekData.SeekRelative = 0;
+ mpvPlugin->Service(MPV_SEEK, &seekData);
+
return;
} else if (Config::GetInstance().UseMpv) {
@@ -189,13 +210,6 @@ void cMyPlugin::PlayFile(plexclient::Video Vid)
isyslog("[plex]: play file '%s'\n", Vid.m_sKey.c_str());
- if(Vid.m_iMyPlayOffset == 0 && Vid.m_lViewoffset > 0 ) {
- cString message = cString::sprintf(tr("To start from %ld minutes, press Ok."), Vid.m_lViewoffset / 60000);
- eKeys response = Skins.Message(eMessageType::mtInfo, message, 5);
- if(response == kOk) {
- Vid.m_iMyPlayOffset = Vid.m_lViewoffset/1000;
- }
- }
cControl* control = cHlsPlayerControl::Create(Vid);
if(control) {
cControl::Launch(control);
diff --git a/plex.h b/plex.h
index 097f0ad..13d529f 100644
--- a/plex.h
+++ b/plex.h
@@ -55,7 +55,9 @@ public:
virtual cOsdObject *MainMenuAction(void);
virtual cMenuSetupPage *SetupMenu(void);
virtual bool SetupParse(const char *, const char *);
-
+
+ static plexclient::Video CurrentVideo;
+ static bool PlayingFile;
static void PlayFile(plexclient::Video Vid);
public:
diff --git a/services.h b/services.h
index eea4641..c26ffba 100644
--- a/services.h
+++ b/services.h
@@ -1,6 +1,7 @@
#pragma once
#define MPV_PLAY_FILE "Mpv_PlayFile"
#define MPV_SET_TITLE "Mpv_SetTitle"
+#define MPV_SEEK "Mpv_Seek"
// play the given Filename, this can be a media file or a playlist
typedef struct
@@ -14,3 +15,9 @@ typedef struct
{
char *Title;
} Mpv_SetTitle;
+
+typedef struct
+{
+ int SeekAbsolute;
+ int SeekRelative;
+} Mpv_Seek; \ No newline at end of file