001/* 002 * Copyright (C) 2013-2014 Zhang Rui <bbcallen@gmail.com> 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.baidu.cloud.media.player; 018 019import android.annotation.TargetApi; 020import android.content.Context; 021import android.net.Uri; 022import android.os.Build; 023import android.view.Surface; 024import android.view.SurfaceHolder; 025 026import java.io.FileDescriptor; 027import java.io.IOException; 028import java.util.Map; 029 030import com.baidu.cloud.media.player.misc.IMediaDataSource; 031import com.baidu.cloud.media.player.misc.ITrackInfo; 032 033public interface IMediaPlayer { 034 /* 035 * Do not change these values without updating their counterparts in native 036 */ 037 int MEDIA_INFO_UNKNOWN = 1; 038 int MEDIA_INFO_STARTED_AS_NEXT = 2; 039 int MEDIA_INFO_VIDEO_RENDERING_START = 3; 040 int MEDIA_INFO_VIDEO_TRACK_LAGGING = 700; 041 int MEDIA_INFO_BUFFERING_START = 701; 042 int MEDIA_INFO_BUFFERING_END = 702; 043 int MEDIA_INFO_NETWORK_BANDWIDTH = 703; 044 int MEDIA_INFO_BAD_INTERLEAVING = 800; 045 int MEDIA_INFO_NOT_SEEKABLE = 801; 046 int MEDIA_INFO_METADATA_UPDATE = 802; 047 int MEDIA_INFO_TIMED_TEXT_ERROR = 900; 048 int MEDIA_INFO_UNSUPPORTED_SUBTITLE = 901; 049 int MEDIA_INFO_SUBTITLE_TIMED_OUT = 902; 050 051 int MEDIA_INFO_VIDEO_ROTATION_CHANGED = 10001; 052 int MEDIA_INFO_AUDIO_RENDERING_START = 10002; 053 054 int MEDIA_ERROR_UNKNOWN = 1; 055 int MEDIA_ERROR_SERVER_DIED = 100; 056 int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200; 057 int MEDIA_ERROR_IO = -1004; 058 int MEDIA_ERROR_MALFORMED = -1007; 059 int MEDIA_ERROR_UNSUPPORTED = -1010; 060 int MEDIA_ERROR_TIMED_OUT = -110; 061 062 void setDisplay(SurfaceHolder sh); 063 064 void setDataSource(Context context, Uri uri) 065 throws IOException, IllegalArgumentException, SecurityException, IllegalStateException; 066 067 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) 068 void setDataSource(Context context, Uri uri, Map<String, String> headers) 069 throws IOException, IllegalArgumentException, SecurityException, IllegalStateException; 070 071 void setDataSource(FileDescriptor fd) throws IOException, IllegalArgumentException, IllegalStateException; 072 073 void setDataSource(String path) 074 throws IOException, IllegalArgumentException, SecurityException, IllegalStateException; 075 076 String getDataSource(); 077 078 void prepareAsync() throws IllegalStateException; 079 080 void start() throws IllegalStateException; 081 082 void stop() throws IllegalStateException; 083 084 void pause() throws IllegalStateException; 085 086 void setScreenOnWhilePlaying(boolean screenOn); 087 088 int getVideoWidth(); 089 090 int getVideoHeight(); 091 092 boolean isPlaying(); 093 094 void seekTo(long msec) throws IllegalStateException; 095 096 long getCurrentPosition(); 097 098 long getDuration(); 099 100 void release(); 101 102 void reset(); 103 104 void setVolume(float leftVolume, float rightVolume); 105 106 int getAudioSessionId(); 107 108 MediaInfo getMediaInfo(); 109 110 @SuppressWarnings("EmptyMethod") 111 @Deprecated 112 void setLogEnabled(boolean enable); 113 114 @Deprecated 115 boolean isPlayable(); 116 117 void setOnPreparedListener(OnPreparedListener listener); 118 119 void setOnCompletionListener(OnCompletionListener listener); 120 121 void setOnBufferingUpdateListener(OnBufferingUpdateListener listener); 122 123 void setOnSeekCompleteListener(OnSeekCompleteListener listener); 124 125 void setOnVideoSizeChangedListener(OnVideoSizeChangedListener listener); 126 127 void setOnErrorListener(OnErrorListener listener); 128 129 void setOnInfoListener(OnInfoListener listener); 130 131 /*-------------------- 132 * Listeners 133 */ 134 interface OnPreparedListener { 135 void onPrepared(IMediaPlayer mp); 136 } 137 138 interface OnCompletionListener { 139 void onCompletion(IMediaPlayer mp); 140 } 141 142 interface OnBufferingUpdateListener { 143 void onBufferingUpdate(IMediaPlayer mp, int percent); 144 } 145 146 interface OnSeekCompleteListener { 147 void onSeekComplete(IMediaPlayer mp); 148 } 149 150 interface OnVideoSizeChangedListener { 151 void onVideoSizeChanged(IMediaPlayer mp, int width, int height, int sar_num, int sar_den); 152 } 153 154 interface OnErrorListener { 155 boolean onError(IMediaPlayer mp, int what, int extra); 156 } 157 158 interface OnInfoListener { 159 boolean onInfo(IMediaPlayer mp, int what, int extra); 160 } 161 162 /*-------------------- 163 * Optional 164 */ 165 void setAudioStreamType(int streamtype); 166 167 @Deprecated 168 void setKeepInBackground(boolean keepInBackground); 169 170 int getVideoSarNum(); 171 172 int getVideoSarDen(); 173 174 @Deprecated 175 void setWakeMode(Context context, int mode); 176 177 void setLooping(boolean looping); 178 179 boolean isLooping(); 180 181 /*-------------------- 182 * AndroidMediaPlayer: JELLY_BEAN 183 */ 184 ITrackInfo[] getTrackInfo(); 185 186 /*-------------------- 187 * AndroidMediaPlayer: ICE_CREAM_SANDWICH: 188 */ 189 void setSurface(Surface surface); 190 191 /*-------------------- 192 * AndroidMediaPlayer: M: 193 */ 194 void setDataSource(IMediaDataSource mediaDataSource); 195}