Changeset 165552 in webkit
- Timestamp:
- Mar 13, 2014 11:24:06 AM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r165549 r165552 1 2014-03-12 Eric Carlson <eric.carlson@apple.com> 2 3 [iOS] Sync media playback with now playing 4 https://bugs.webkit.org/show_bug.cgi?id=130172 5 6 Reviewed by Jer Noble. 7 8 * html/HTMLMediaElement.cpp: 9 (WebCore::HTMLMediaElement::play): Move clientWillBeginPlayback to 10 playInternal so it is called every time playback begins. 11 (WebCore::HTMLMediaElement::playInternal): Call clientWillBeginPlayback. 12 (WebCore::HTMLMediaElement::pause): Move clientWillPausePlayback to 13 playInternal so it is called every time playback begins. 14 (WebCore::HTMLMediaElement::playInternal): Call clientWillPausePlayback. 15 (WebCore::HTMLMediaElement::mediaSessionTitle): New. Return the 'title' attribute, 16 or currenSrc if that is empty. 17 * html/HTMLMediaElement.h: 18 (WebCore::HTMLMediaElement::mediaSessionDuration): Return duration. 19 (WebCore::HTMLMediaElement::mediaSessionCurrentTime): Return current time. 20 21 * platform/audio/MediaSession.cpp: 22 (WebCore::MediaSession::clientWillPausePlayback): New, passthrough to the 23 media element. 24 (WebCore::MediaSession::title): Ditto. 25 (WebCore::MediaSession::duration): Ditto. 26 (WebCore::MediaSession::currentTime): Ditto. 27 * platform/audio/MediaSession.h: 28 (WebCore::MediaSessionClient::mediaSessionTitle): 29 (WebCore::MediaSessionClient::mediaSessionDuration): 30 (WebCore::MediaSessionClient::mediaSessionCurrentTime): 31 32 * platform/audio/MediaSessionManager.cpp: 33 (WebCore::MediaSessionManager::MediaSessionManager): Initialize m_activeSession. 34 (WebCore::MediaSessionManager::removeSession): Set m_activeSession if the session 35 being removed is currently active. 36 (WebCore::MediaSessionManager::sessionWillBeginPlayback): Set m_activeSession. 37 * platform/audio/MediaSessionManager.h: 38 (WebCore::MediaSessionManager::sessionWillEndPlayback): 39 (WebCore::MediaSessionManager::setCurrentSession): 40 (WebCore::MediaSessionManager::currentSession): 41 42 * platform/audio/ios/MediaSessionManagerIOS.h: 43 * platform/audio/ios/MediaSessionManagerIOS.mm: 44 (WebCore::MediaSessionManageriOS::sessionWillBeginPlayback): Call updateNowPlayingInfo. 45 (WebCore::MediaSessionManageriOS::sessionWillEndPlayback): Ditto. 46 (WebCore::MediaSessionManageriOS::updateNowPlayingInfo): Update MPNowPlayingInfoCenter 47 with the current media item's title, duration, and current time. 48 (-[WebMediaSessionHelper initWithCallback:]): Turn on deliver of remote control 49 events, even though we don't respond to them yet, or Now Playing won't work. 50 1 51 2014-03-13 Radu Stavila <stavila@adobe.com> 2 52 -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r165344 r165552 2685 2685 removeBehaviorsRestrictionsAfterFirstUserGesture(); 2686 2686 2687 playInternal(); 2688 } 2689 2690 void HTMLMediaElement::playInternal() 2691 { 2692 LOG(Media, "HTMLMediaElement::playInternal"); 2693 2687 2694 if (!m_mediaSession->clientWillBeginPlayback()) { 2688 2695 LOG(Media, " returning because of interruption"); … … 2690 2697 } 2691 2698 2692 playInternal();2693 }2694 2695 void HTMLMediaElement::playInternal()2696 {2697 LOG(Media, "HTMLMediaElement::playInternal");2698 2699 2699 // 4.8.10.9. Playing the media resource 2700 2700 if (!m_player || m_networkState == NETWORK_EMPTY) … … 2732 2732 return; 2733 2733 2734 pauseInternal(); 2735 } 2736 2737 2738 void HTMLMediaElement::pauseInternal() 2739 { 2740 LOG(Media, "HTMLMediaElement::pauseInternal"); 2741 2734 2742 if (!m_mediaSession->clientWillPausePlayback()) { 2735 2743 LOG(Media, " returning because of interruption"); 2736 2744 return; 2737 2745 } 2738 2739 pauseInternal(); 2740 } 2741 2742 2743 void HTMLMediaElement::pauseInternal() 2744 { 2745 LOG(Media, "HTMLMediaElement::pauseInternal"); 2746 2746 2747 2747 // 4.8.10.9. Playing the media resource 2748 2748 if (!m_player || m_networkState == NETWORK_EMPTY) { … … 5879 5879 play(); 5880 5880 } 5881 5882 } 5883 5884 #endif 5881 5882 String HTMLMediaElement::mediaSessionTitle() const 5883 { 5884 if (fastHasAttribute(titleAttr)) 5885 return fastGetAttribute(titleAttr); 5886 5887 return m_currentSrc; 5888 } 5889 5890 } 5891 5892 #endif -
trunk/Source/WebCore/html/HTMLMediaElement.h
r165344 r165552 691 691 #endif 692 692 693 // MediaSessionClient Overrides 693 694 virtual MediaSession::MediaType mediaType() const override; 694 695 virtual void pausePlayback() override; 695 696 virtual void resumePlayback() override; 697 virtual String mediaSessionTitle() const override; 698 virtual double mediaSessionDuration() const override { return duration(); } 699 virtual double mediaSessionCurrentTime() const override { return currentTime(); } 696 700 697 701 Timer<HTMLMediaElement> m_loadTimer; -
trunk/Source/WebCore/platform/audio/MediaSession.cpp
r163971 r165552 116 116 117 117 setState(Paused); 118 MediaSessionManager::sharedManager().sessionWillEndPlayback(*this); 118 119 return true; 119 120 } … … 129 130 return m_client.mediaType(); 130 131 } 132 133 String MediaSession::title() const 134 { 135 return m_client.mediaSessionTitle(); 136 } 137 138 double MediaSession::duration() const 139 { 140 return m_client.mediaSessionDuration(); 141 } 142 143 double MediaSession::currentTime() const 144 { 145 return m_client.mediaSessionCurrentTime(); 146 } 131 147 132 148 } -
trunk/Source/WebCore/platform/audio/MediaSession.h
r163390 r165552 27 27 #define MediaSession_h 28 28 29 #include "MediaPlayer.h" 29 30 #include <wtf/Noncopyable.h> 30 31 … … 71 72 72 73 void pauseSession(); 74 75 String title() const; 76 double duration() const; 77 double currentTime() const; 73 78 74 79 protected: … … 90 95 virtual void resumePlayback() = 0; 91 96 virtual void pausePlayback() = 0; 92 97 98 virtual String mediaSessionTitle() const { return String(); } 99 virtual double mediaSessionDuration() const { return MediaPlayer::invalidTime(); } 100 virtual double mediaSessionCurrentTime() const { return MediaPlayer::invalidTime(); } 101 93 102 protected: 94 103 virtual ~MediaSessionClient() { } -
trunk/Source/WebCore/platform/audio/MediaSessionManager.cpp
r163657 r165552 41 41 42 42 MediaSessionManager::MediaSessionManager() 43 : m_interrupted(false) 43 : m_activeSession(nullptr) 44 , m_interrupted(false) 44 45 { 45 46 resetRestrictions(); … … 110 111 if (index == notFound) 111 112 return; 112 113 114 if (m_activeSession == &session) 115 setCurrentSession(nullptr); 116 113 117 m_sessions.remove(index); 114 118 updateSessionState(); … … 133 137 } 134 138 135 void MediaSessionManager::sessionWillBeginPlayback(const MediaSession& session) const139 void MediaSessionManager::sessionWillBeginPlayback(const MediaSession& session) 136 140 { 141 setCurrentSession(&session); 142 137 143 MediaSession::MediaType sessionType = session.mediaType(); 138 144 SessionRestrictions restrictions = m_restrictions[sessionType]; -
trunk/Source/WebCore/platform/audio/MediaSessionManager.h
r164661 r165552 66 66 virtual void resetRestrictions(); 67 67 68 void sessionWillBeginPlayback(const MediaSession&) const; 69 68 virtual void sessionWillBeginPlayback(const MediaSession&); 69 virtual void sessionWillEndPlayback(const MediaSession&) { } 70 70 71 bool sessionRestrictsInlineVideoPlayback(const MediaSession&) const; 71 72 … … 80 81 void addSession(MediaSession&); 81 82 void removeSession(MediaSession&); 82 83 84 void setCurrentSession(const MediaSession* session) { m_activeSession = session; } 85 const MediaSession* currentSession() { return m_activeSession; } 86 83 87 private: 84 88 void updateSessionState(); … … 87 91 88 92 Vector<MediaSession*> m_sessions; 93 const MediaSession* m_activeSession; 89 94 bool m_interrupted; 90 95 }; -
trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h
r165028 r165552 49 49 friend class MediaSessionManager; 50 50 51 virtual void sessionWillBeginPlayback(const MediaSession&) override; 52 virtual void sessionWillEndPlayback(const MediaSession&) override; 53 54 void updateNowPlayingInfo(); 55 51 56 virtual void resetRestrictions() override; 52 57 -
trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm
r165028 r165552 36 36 #import "WebCoreThreadRun.h" 37 37 #import <AVFoundation/AVAudioSession.h> 38 #import <MediaPlayer/MPMediaItem.h> 39 #import <MediaPlayer/MPNowPlayingInfoCenter.h> 38 40 #import <UIKit/UIApplication.h> 39 41 #import <objc/runtime.h> … … 41 43 42 44 SOFT_LINK_FRAMEWORK(AVFoundation) 43 SOFT_LINK_FRAMEWORK(UIKit)44 45 45 SOFT_LINK_CLASS(AVFoundation, AVAudioSession) 46 47 46 SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionNotification, NSString *) 48 47 SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionTypeKey, NSString *) 49 48 SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionOptionKey, NSString *) 50 SOFT_LINK_POINTER(UIKit, UIApplicationWillResignActiveNotification, NSString *)51 SOFT_LINK_POINTER(UIKit, UIApplicationWillEnterForegroundNotification, NSString *)52 SOFT_LINK_POINTER(UIKit, UIApplicationDidBecomeActiveNotification, NSString *)53 49 54 50 #define AVAudioSession getAVAudioSessionClass() … … 56 52 #define AVAudioSessionInterruptionTypeKey getAVAudioSessionInterruptionTypeKey() 57 53 #define AVAudioSessionInterruptionOptionKey getAVAudioSessionInterruptionOptionKey() 54 55 SOFT_LINK_FRAMEWORK(UIKit) 56 SOFT_LINK_CLASS(UIKit, UIApplication) 57 SOFT_LINK_POINTER(UIKit, UIApplicationWillResignActiveNotification, NSString *) 58 SOFT_LINK_POINTER(UIKit, UIApplicationWillEnterForegroundNotification, NSString *) 59 SOFT_LINK_POINTER(UIKit, UIApplicationDidBecomeActiveNotification, NSString *) 60 61 #define UIApplication getUIApplicationClass() 58 62 #define UIApplicationWillResignActiveNotification getUIApplicationWillResignActiveNotification() 59 63 #define UIApplicationWillEnterForegroundNotification getUIApplicationWillEnterForegroundNotification() 60 64 #define UIApplicationDidBecomeActiveNotification getUIApplicationDidBecomeActiveNotification() 65 66 SOFT_LINK_FRAMEWORK(MediaPlayer) 67 SOFT_LINK_CLASS(MediaPlayer, MPNowPlayingInfoCenter) 68 SOFT_LINK_POINTER(MediaPlayer, MPMediaItemPropertyTitle, NSString *) 69 SOFT_LINK_POINTER(MediaPlayer, MPMediaItemPropertyPlaybackDuration, NSString *) 70 SOFT_LINK_POINTER(MediaPlayer, MPNowPlayingInfoPropertyElapsedPlaybackTime, NSString *) 71 SOFT_LINK_POINTER(MediaPlayer, MPNowPlayingInfoPropertyPlaybackRate, NSString *) 72 73 #define MPMediaItemPropertyTitle getMPMediaItemPropertyTitle() 74 #define MPMediaItemPropertyPlaybackDuration getMPMediaItemPropertyPlaybackDuration() 75 #define MPNowPlayingInfoPropertyElapsedPlaybackTime getMPNowPlayingInfoPropertyElapsedPlaybackTime() 76 #define MPNowPlayingInfoPropertyPlaybackRate getMPNowPlayingInfoPropertyPlaybackRate() 61 77 62 78 NSString* WebUIApplicationWillResignActiveNotification = @"WebUIApplicationWillResignActiveNotification"; … … 120 136 } 121 137 #endif 138 139 void MediaSessionManageriOS::sessionWillBeginPlayback(const MediaSession& session) 140 { 141 MediaSessionManager::sessionWillBeginPlayback(session); 142 updateNowPlayingInfo(); 143 } 144 145 void MediaSessionManageriOS::sessionWillEndPlayback(const MediaSession& session) 146 { 147 MediaSessionManager::sessionWillEndPlayback(session); 148 updateNowPlayingInfo(); 149 } 150 151 void MediaSessionManageriOS::updateNowPlayingInfo() 152 { 153 MPNowPlayingInfoCenter *nowPlaying = (MPNowPlayingInfoCenter *)[getMPNowPlayingInfoCenterClass() defaultCenter]; 154 const MediaSession* currentSession = this->currentSession(); 155 156 if (!currentSession) { 157 [nowPlaying setNowPlayingInfo:nil]; 158 return; 159 } 160 161 RetainPtr<NSMutableDictionary> info = adoptNS([[NSMutableDictionary alloc] init]); 162 163 String title = currentSession->title(); 164 if (!title.isEmpty()) 165 [info setValue:static_cast<NSString *>(title) forKey:MPMediaItemPropertyTitle]; 166 167 double duration = currentSession->duration(); 168 if (std::isfinite(duration) && duration != MediaPlayer::invalidTime()) 169 [info setValue:@(duration) forKey:MPMediaItemPropertyPlaybackDuration]; 170 171 double currentTime = currentSession->currentTime(); 172 if (std::isfinite(currentTime)) 173 [info setValue:@(currentTime) forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]; 174 175 [info setValue:(currentSession->state() == MediaSession::Playing ? @YES : @NO) forKey:MPNowPlayingInfoPropertyPlaybackRate]; 176 [nowPlaying setNowPlayingInfo:info.get()]; 177 } 122 178 123 179 } // namespace WebCore … … 135 191 [center addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]]; 136 192 137 // FIXME: These need to be piped through from the UI process in WK2 mode.138 193 [center addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; 139 194 [center addObserver:self selector:@selector(applicationWillEnterForeground:) name:WebUIApplicationWillEnterForegroundNotification object:nil]; … … 142 197 [center addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil]; 143 198 [center addObserver:self selector:@selector(applicationWillResignActive:) name:WebUIApplicationWillResignActiveNotification object:nil]; 144 199 200 // Now playing won't work unless we turn on the delivery of remote control events. 201 [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 202 145 203 return self; 146 204 }
Note: See TracChangeset
for help on using the changeset viewer.