Skip to content

Commit fb0730e

Browse files
committed
Add mediaPlayerPlaybackStateChanged to MediaPlayerClient
Reviewed by Eric Carlson. https://bugs.webkit.org/show_bug.cgi?id=45263 The platform backend may change state, for example as a result of an external plugin controlling the backend, so we need to react to this situation by syncing up the WebCore state with the platform backend. We call playInternal()/pauseInternal() depending on the backend state, to trigger the corresponding DOM events to match the state. updatePlayState() is then refactored to take into account the situation where the backend is already in the correct state but WebCore is not, so that we update the playback progress timer and set m_playing correctly. updatePlayState() changes Should be covered by existing tests. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::mediaPlayerPlaybackStateChanged): (WebCore::HTMLMediaElement::updatePlayState): * html/HTMLMediaElement.h: * platform/graphics/MediaPlayer.cpp: (WebCore::MediaPlayer::playbackStateChanged): * platform/graphics/MediaPlayer.h: (WebCore::MediaPlayerClient::mediaPlayerPlaybackStateChanged): Canonical link: https://commits.webkit.org/57714@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@66961 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 0f39641 commit fb0730e

File tree

5 files changed

+74
-9
lines changed

5 files changed

+74
-9
lines changed

WebCore/ChangeLog

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
2010-09-06 Tor Arne Vestbø <tor.arne.vestbo@nokia.com>
2+
3+
Reviewed by Eric Carlson.
4+
5+
Add mediaPlayerPlaybackStateChanged to MediaPlayerClient
6+
7+
https://bugs.webkit.org/show_bug.cgi?id=45263
8+
9+
The platform backend may change state, for example as a result
10+
of an external plugin controlling the backend, so we need to
11+
react to this situation by syncing up the WebCore state with the
12+
platform backend.
13+
14+
We call playInternal()/pauseInternal() depending on the backend
15+
state, to trigger the corresponding DOM events to match the state.
16+
17+
updatePlayState() is then refactored to take into account the
18+
situation where the backend is already in the correct state but
19+
WebCore is not, so that we update the playback progress timer
20+
and set m_playing correctly.
21+
22+
updatePlayState() changes Should be covered by existing tests.
23+
24+
* html/HTMLMediaElement.cpp:
25+
(WebCore::HTMLMediaElement::mediaPlayerPlaybackStateChanged):
26+
(WebCore::HTMLMediaElement::updatePlayState):
27+
* html/HTMLMediaElement.h:
28+
* platform/graphics/MediaPlayer.cpp:
29+
(WebCore::MediaPlayer::playbackStateChanged):
30+
* platform/graphics/MediaPlayer.h:
31+
(WebCore::MediaPlayerClient::mediaPlayerPlaybackStateChanged):
32+
133
2010-09-08 Adam Barth <abarth@webkit.org>
234

335
Reviewed by Eric Seidel.

WebCore/html/HTMLMediaElement.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,19 @@ void HTMLMediaElement::mediaPlayerRateChanged(MediaPlayer*)
16001600
endProcessingMediaPlayerCallback();
16011601
}
16021602

1603+
void HTMLMediaElement::mediaPlayerPlaybackStateChanged(MediaPlayer*)
1604+
{
1605+
if (!m_player)
1606+
return;
1607+
1608+
beginProcessingMediaPlayerCallback();
1609+
if (m_player->paused())
1610+
pauseInternal();
1611+
else
1612+
playInternal();
1613+
endProcessingMediaPlayerCallback();
1614+
}
1615+
16031616
void HTMLMediaElement::mediaPlayerSawUnsupportedTracks(MediaPlayer*)
16041617
{
16051618
// The MediaPlayer came across content it cannot completely handle.
@@ -1775,24 +1788,33 @@ void HTMLMediaElement::updatePlayState()
17751788

17761789
bool shouldBePlaying = potentiallyPlaying();
17771790
bool playerPaused = m_player->paused();
1778-
if (shouldBePlaying && playerPaused) {
1791+
1792+
if (shouldBePlaying) {
17791793
setDisplayMode(Video);
17801794

1781-
// Set rate before calling play in case the rate was set before the media engine wasn't setup.
1782-
// The media engine should just stash the rate since it isn't already playing.
1783-
m_player->setRate(m_playbackRate);
1784-
m_player->play();
1795+
if (playerPaused) {
1796+
// Set rate before calling play in case the rate was set before the media engine was setup.
1797+
// The media engine should just stash the rate since it isn't already playing.
1798+
m_player->setRate(m_playbackRate);
1799+
m_player->play();
1800+
}
1801+
17851802
startPlaybackProgressTimer();
17861803
m_playing = true;
1787-
} else if (!shouldBePlaying && !playerPaused) {
1788-
m_player->pause();
1804+
1805+
} else { // Should not be playing right now
1806+
if (!playerPaused)
1807+
m_player->pause();
1808+
17891809
m_playbackProgressTimer.stop();
17901810
m_playing = false;
17911811
float time = currentTime();
17921812
if (time > m_lastSeekTime)
17931813
addPlayedRange(m_lastSeekTime, time);
1794-
} else if (couldPlayIfEnoughData() && playerPaused)
1795-
m_player->prepareToPlay();
1814+
1815+
if (couldPlayIfEnoughData())
1816+
m_player->prepareToPlay();
1817+
}
17961818

17971819
if (renderer())
17981820
renderer()->updateFromElement();

WebCore/html/HTMLMediaElement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, private M
219219
virtual void mediaPlayerMuteChanged(MediaPlayer*);
220220
virtual void mediaPlayerDurationChanged(MediaPlayer*);
221221
virtual void mediaPlayerRateChanged(MediaPlayer*);
222+
virtual void mediaPlayerPlaybackStateChanged(MediaPlayer*);
222223
virtual void mediaPlayerSawUnsupportedTracks(MediaPlayer*);
223224
virtual void mediaPlayerRepaint(MediaPlayer*);
224225
virtual void mediaPlayerSizeChanged(MediaPlayer*);

WebCore/platform/graphics/MediaPlayer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,12 @@ void MediaPlayer::rateChanged()
694694
m_mediaPlayerClient->mediaPlayerRateChanged(this);
695695
}
696696

697+
void MediaPlayer::playbackStateChanged()
698+
{
699+
if (m_mediaPlayerClient)
700+
m_mediaPlayerClient->mediaPlayerPlaybackStateChanged(this);
701+
}
702+
697703
}
698704

699705
#endif

WebCore/platform/graphics/MediaPlayer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class MediaPlayerClient {
121121
// the playback rate has changed
122122
virtual void mediaPlayerRateChanged(MediaPlayer*) { }
123123

124+
// the play/pause status changed
125+
virtual void mediaPlayerPlaybackStateChanged(MediaPlayer*) { }
126+
124127
// The MediaPlayer has found potentially problematic media content.
125128
// This is used internally to trigger swapping from a <video>
126129
// element to an <embed> in standalone documents
@@ -241,6 +244,7 @@ class MediaPlayer : public Noncopyable {
241244
void timeChanged();
242245
void sizeChanged();
243246
void rateChanged();
247+
void playbackStateChanged();
244248
void durationChanged();
245249

246250
void repaint();

0 commit comments

Comments
 (0)