1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ 6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ 7 8 #include <jni.h> 9 #include <string> 10 11 #include "base/callback.h" 12 #include "base/time/time.h" 13 #include "media/base/media_export.h" 14 #include "ui/gl/android/scoped_java_surface.h" 15 #include "url/gurl.h" 16 17 namespace media { 18 19 class MediaDrmBridge; 20 class MediaPlayerManager; 21 22 // This class serves as the base class for different media player 23 // implementations on Android. Subclasses need to provide their own 24 // MediaPlayerAndroid::Create() implementation. 25 class MEDIA_EXPORT MediaPlayerAndroid { 26 public: 27 virtual ~MediaPlayerAndroid(); 28 29 // Error types for MediaErrorCB. 30 enum MediaErrorType { 31 MEDIA_ERROR_FORMAT, 32 MEDIA_ERROR_DECODE, 33 MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK, 34 MEDIA_ERROR_INVALID_CODE, 35 }; 36 37 // Passing an external java surface object to the player. 38 virtual void SetVideoSurface(gfx::ScopedJavaSurface surface) = 0; 39 40 // Start playing the media. 41 virtual void Start() = 0; 42 43 // Pause the media. 44 virtual void Pause(bool is_media_related_action) = 0; 45 46 // Seek to a particular position, based on renderer signaling actual seek 47 // with MediaPlayerHostMsg_Seek. If eventual success, OnSeekComplete() will be 48 // called. 49 virtual void SeekTo(const base::TimeDelta& timestamp) = 0; 50 51 // Release the player resources. 52 virtual void Release() = 0; 53 54 // Set the player volume. 55 virtual void SetVolume(double volume) = 0; 56 57 // Get the media information from the player. 58 virtual bool IsRemote() const; 59 virtual int GetVideoWidth() = 0; 60 virtual int GetVideoHeight() = 0; 61 virtual base::TimeDelta GetDuration() = 0; 62 virtual base::TimeDelta GetCurrentTime() = 0; 63 virtual bool IsPlaying() = 0; 64 virtual bool IsPlayerReady() = 0; 65 virtual bool CanPause() = 0; 66 virtual bool CanSeekForward() = 0; 67 virtual bool CanSeekBackward() = 0; 68 virtual GURL GetUrl(); 69 virtual GURL GetFirstPartyForCookies(); 70 71 // Pass a drm bridge to a player. 72 virtual void SetDrmBridge(MediaDrmBridge* drm_bridge); 73 74 // Notifies the player that a decryption key has been added. The player 75 // may want to start/resume playback if it is waiting for a key. 76 virtual void OnKeyAdded(); 77 player_id()78 int player_id() { return player_id_; } 79 80 protected: 81 MediaPlayerAndroid(int player_id, 82 MediaPlayerManager* manager); 83 manager()84 MediaPlayerManager* manager() { return manager_; } 85 86 private: 87 // Player ID assigned to this player. 88 int player_id_; 89 90 // Resource manager for all the media players. 91 MediaPlayerManager* manager_; 92 93 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid); 94 }; 95 96 } // namespace media 97 98 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ 99