Browse Source

PlayerComponent: avoid that host and web go out of sync

This fixes the problems with playback not starting.

It turns out that if during loading a pause command is accidentally
sent, the host will go into pause mode. Playback will start paused, as
if web specified autoPlay=false. Web doesn't expect this, and implicitly
assumes that playback is _not_ paused. As a result, web is stuck and
can't unpause, because it thinks playback is active.

Another part of the problem is that a pause command is accidentally
sent. This might be a result of key autorepeat triggering too quickly.
If the user hits "enter" in the preplay screen, "enter" might get
repeated after playback/loading logically starts, resulting in the pause
command.

This commit happens to workaround both issues by forcing the pause state
back to the autoPlay parameter specified by web on loading. Any pause
commands sent during loading will essentially be overridden.

We need to fix these things properly, but it will take time.
Vincent Lang 9 years ago
parent
commit
28b275ccc2
2 changed files with 8 additions and 2 deletions
  1. 7 2
      src/player/PlayerComponent.cpp
  2. 1 0
      src/player/PlayerComponent.h

+ 7 - 2
src/player/PlayerComponent.cpp

@@ -34,7 +34,7 @@ static void wakeup_cb(void *context)
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 PlayerComponent::PlayerComponent(QObject* parent)
-  : ComponentBase(parent), m_lastPositionUpdate(0.0), m_playbackAudioDelay(0), m_playbackStartSent(false), m_window(nullptr), m_mediaFrameRate(0),
+  : ComponentBase(parent), m_lastPositionUpdate(0.0), m_playbackAudioDelay(0), m_playbackStartSent(false), m_autoPlay(false),  m_window(nullptr), m_mediaFrameRate(0),
   m_restoreDisplayTimer(this), m_reloadAudioTimer(this),
   m_streamSwitchImminent(false), m_doAc3Transcoding(false)
 {
@@ -273,7 +273,8 @@ void PlayerComponent::queueMedia(const QString& url, const QVariantMap& options,
   if (!audioStream.isEmpty())
     extraArgs.insert("ff-aid", audioStream);
 
-  extraArgs.insert("pause", options["autoplay"].toBool() ? "no" : "yes");
+  m_autoPlay = options["autoplay"].toBool();
+  extraArgs.insert("pause", m_autoPlay ? "no" : "yes");
 
   QString userAgent = metadata["headers"].toMap()["User-Agent"].toString();
   if (userAgent.size())
@@ -402,7 +403,11 @@ void PlayerComponent::handleMpvEvent(mpv_event *event)
     {
       // it's also sent after seeks are completed
       if (!m_playbackStartSent)
+      {
+        mpv::qt::set_property_variant(m_mpv, "pause", !m_autoPlay);
+        emit paused(!m_autoPlay);
         emit playbackStarting();
+      }
       m_playbackStartSent = true;
       break;
     }

+ 1 - 0
src/player/PlayerComponent.h

@@ -200,6 +200,7 @@ private:
   qint64 m_playbackAudioDelay;
   QString m_currentUrl;
   bool m_playbackStartSent;
+  bool m_autoPlay;
   QQuickWindow* m_window;
   float m_mediaFrameRate;
   QTimer m_restoreDisplayTimer;