OSDN Git Service

Add poster support and other fixes
authorAndrei Popescu <andreip@google.com>
Tue, 15 Sep 2009 12:09:27 +0000 (13:09 +0100)
committerAndrei Popescu <andreip@google.com>
Thu, 17 Sep 2009 10:28:35 +0000 (11:28 +0100)
WebCore/html/HTMLMediaElement.cpp
WebCore/platform/graphics/MediaPlayer.cpp
WebCore/platform/graphics/MediaPlayer.h
WebCore/platform/graphics/MediaPlayerPrivate.h
WebCore/platform/graphics/android/MediaPlayerPrivateAndroid.h
WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp

index b2e6428..17a3110 100644 (file)
@@ -554,7 +554,15 @@ void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType)
     updateVolume();
 
     m_player->load(m_currentSrc, contentType);
-    
+
+#if PLATFORM(ANDROID)
+    if (isVideo() && m_player->canLoadPoster()) {
+        KURL posterUrl = static_cast<HTMLVideoElement*>(this)->poster();
+        if (!posterUrl.isEmpty())
+            m_player->setPoster(posterUrl);
+    }
+#endif
+
     if (renderer())
         renderer()->updateFromElement();
 }
index 6205a7b..15815dc 100644 (file)
@@ -104,6 +104,11 @@ public:
 
     virtual void paint(GraphicsContext*, const IntRect&) { }
 
+#if PLATFORM(ANDROID)
+    virtual bool canLoadPoster() const { return false; }
+    virtual void setPoster(const String&) { }
+#endif
+
 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
     virtual void setPoster(const String& /*url*/) { }
     virtual void deliverNotification(MediaPlayerProxyNotificationType) { }
@@ -253,11 +258,18 @@ void MediaPlayer::load(const String& url, const ContentType& contentType)
         m_private.set(createNullMediaPlayer(this));
 }    
 
-#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
+#if PLATFORM(ANDROID)
+bool MediaPlayer::canLoadPoster() const
+{
+    return m_private->canLoadPoster();
+}
+#endif
+
+#if ENABLE(PLUGIN_PROXY_FOR_VIDEO) || PLATFORM(ANDROID)
 void MediaPlayer::setPoster(const String& url)
 {
     m_private->setPoster(url);
-}    
+}
 #endif
 
 void MediaPlayer::cancelLoad()
index 7f5f2a0..1cb7625 100644 (file)
@@ -184,6 +184,11 @@ public:
 
     MediaPlayerClient* mediaPlayerClient() const { return m_mediaPlayerClient; }
 
+#if PLATFORM(ANDROID)
+    bool canLoadPoster() const;
+    void setPoster(const String&);
+#endif
+
 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
     void setPoster(const String& url);
     void deliverNotification(MediaPlayerProxyNotificationType notification);
index 6d1359b..ba0f4b0 100644 (file)
@@ -92,6 +92,11 @@ public:
 
     virtual void setAutobuffer(bool) { };
 
+#if PLATFORM(ANDROID)
+    virtual bool canLoadPoster() const { return false; }
+    virtual void setPoster(const String&) { }
+#endif
+
 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
     virtual void setPoster(const String& url) = 0;
     virtual void deliverNotification(MediaPlayerProxyNotificationType) = 0;
index 7dcb60d..1dbd20b 100644 (file)
@@ -77,6 +77,9 @@ public:
 
     virtual void setSize(const IntSize&);
 
+    virtual bool canLoadPoster() const { return true; }
+    virtual void setPoster(const String&);
+
     virtual void paint(GraphicsContext*, const IntRect&);
 private:
     // Android-specific methods and fields.
index 2465e29..d6362d0 100644 (file)
@@ -47,6 +47,7 @@ struct MediaPlayerPrivate::JavaGlue
     jmethodID m_createView;
     jmethodID m_attachView;
     jmethodID m_removeView;
+    jmethodID m_setPoster;
 };
 
 MediaPlayerPrivate::~MediaPlayerPrivate()
@@ -99,8 +100,6 @@ void MediaPlayerPrivate::play()
     if (!frameView)
         return;
 
-    WebViewCore* webViewCore =  WebViewCore::getWebViewCore(frameView);
-    ASSERT(webViewCore);
     jstring jUrl = env->NewString((unsigned short *)m_url.characters(), m_url.length());
     env->CallVoidMethod(m_glue->m_javaProxy, m_glue->m_play, jUrl);
     env->DeleteLocalRef(jUrl);
@@ -200,6 +199,17 @@ void MediaPlayerPrivate::setSize(const IntSize&)
 {
 }
 
+void MediaPlayerPrivate::setPoster(const String& url)
+{
+    JNIEnv* env = JSC::Bindings::getJNIEnv();
+     if (!env)
+         return;
+     jstring jUrl = env->NewString((unsigned short *)url.characters(), url.length());
+     env->CallVoidMethod(m_glue->m_javaProxy, m_glue->m_setPoster, jUrl);
+     env->DeleteLocalRef(jUrl);
+     checkException(env);
+}
+
 void MediaPlayerPrivate::paint(GraphicsContext*, const IntRect& r)
 {
     createJavaPlayerIfNeeded();
@@ -242,6 +252,7 @@ MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player) : m_player(player),
     m_glue->m_createView = env->GetMethodID(clazz, "createView", "()V");
     m_glue->m_attachView = env->GetMethodID(clazz, "attachView", "(IIII)V");
     m_glue->m_removeView = env->GetMethodID(clazz, "removeView", "()V");
+    m_glue->m_setPoster = env->GetMethodID(clazz, "loadPoster", "(Ljava/lang/String;)V");
     m_glue->m_javaProxy = NULL;
     env->DeleteLocalRef(clazz);
     // An exception is raised if any of the above fails.