Jelajahi Sumber

Implement speed and time calls for SyncPlay.

Ian Walton 3 tahun lalu
induk
melakukan
901d11502a
4 mengubah file dengan 23 tambahan dan 1 penghapusan
  1. 2 1
      .vscode/settings.json
  2. 2 0
      client-api.md
  3. 15 0
      src/player/PlayerComponent.cpp
  4. 4 0
      src/player/PlayerComponent.h

+ 2 - 1
.vscode/settings.json

@@ -1,6 +1,7 @@
 {
     "files.associations": {
         "optional": "cpp",
-        "system_error": "cpp"
+        "system_error": "cpp",
+        "chrono": "cpp"
     }
 }

+ 2 - 0
client-api.md

@@ -69,6 +69,8 @@ player/PlayerComponent - [header](https://github.com/plexinc/plex-media-player/b
     - subtitleStream: "#" + index from mkv, or pass external url
 - void setAudioDelay(int ms)
 - void setSubtitleDelay(int ms)
+- void setPlaybackRate(int rate) - 1000 = normal speed
+- int getPosition()
 - void setVideoOnlyMode(bool enable) - hides webview
 - bool checkCodecSupport(str codec) - can check for vc1 and mpeg2video
 - list[codecdriver] installedCodecDrivers()

+ 15 - 0
src/player/PlayerComponent.cpp

@@ -946,6 +946,21 @@ void PlayerComponent::setSubtitleDelay(qint64 milliseconds)
   mpv::qt::set_property(m_mpv, "sub-delay", milliseconds / 1000.0);
 }
 
+/////////////////////////////////////////////////////////////////////////////////////////
+void PlayerComponent::setPlaybackRate(int rate)
+{
+  mpv::qt::set_property(m_mpv, "speed", rate / 1000.0);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+qint64 PlayerComponent::getPosition()
+{
+  QVariant time = mpv::qt::get_property(m_mpv, "playback-time");
+  if (time.canConvert(QMetaType::Double))
+    return time.toDouble();
+  return 0;
+}
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // This is called with the set of previous audio devices that were detected, and the set of current
 // audio devices. From this we guess whether we should reopen the audio device. If the user-selected

+ 4 - 0
src/player/PlayerComponent.h

@@ -117,6 +117,10 @@ public:
   // automatically use the whole window. (Same if the rectangle is 0-sized.)
   Q_INVOKABLE void setVideoRectangle(int x, int y, int w, int h);
 
+  Q_INVOKABLE void setPlaybackRate(int rate);
+
+  Q_INVOKABLE qint64 getPosition();
+
   QRect videoRectangle() { return m_videoRectangle; }
 
   const mpv::qt::Handle getMpvHandle() const { return m_mpv; }