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.os.Bundle;
024import android.view.Surface;
025import android.view.SurfaceHolder;
026
027import java.io.FileDescriptor;
028import java.io.IOException;
029import java.util.Map;
030
031import com.baidu.cloud.media.player.misc.IMediaDataSource;
032import com.baidu.cloud.media.player.misc.ITrackInfo;
033
034public interface IMediaPlayer {
035    /*
036     * Do not change these values without updating their counterparts in native
037     */
038    int MEDIA_INFO_UNKNOWN = 1;
039    int MEDIA_INFO_STARTED_AS_NEXT = 2;
040    int MEDIA_INFO_VIDEO_RENDERING_START = 3;
041    int MEDIA_INFO_VIDEO_TRACK_LAGGING = 700;
042    int MEDIA_INFO_BUFFERING_START = 701;
043    int MEDIA_INFO_BUFFERING_END = 702;
044    int MEDIA_INFO_NETWORK_BANDWIDTH = 703;
045    int MEDIA_INFO_BAD_INTERLEAVING = 800;
046    int MEDIA_INFO_NOT_SEEKABLE = 801;
047    int MEDIA_INFO_METADATA_UPDATE = 802;
048    int MEDIA_INFO_TIMED_TEXT_ERROR = 900;
049    int MEDIA_INFO_UNSUPPORTED_SUBTITLE = 901;
050    int MEDIA_INFO_SUBTITLE_TIMED_OUT = 902;
051
052    int MEDIA_INFO_VIDEO_ROTATION_CHANGED = 10001;
053    int MEDIA_INFO_AUDIO_RENDERING_START = 10002;
054
055    int MEDIA_INFO_FRAMECHASING_START = 10003;
056    int MEDIA_INFO_FRAMECHASING_END = 10004;
057
058    int MEDIA_INFO_MEDIA_CHANGE_START = 10005;
059    int MEDIA_INFO_MEDIA_CHANGE_END = 10006;
060
061    int MEDIA_ERROR_UNKNOWN = 1;
062    int MEDIA_ERROR_SERVER_DIED = 100;
063    int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200;
064    int MEDIA_ERROR_IO = -1004;
065    int MEDIA_ERROR_MALFORMED = -1007;
066    int MEDIA_ERROR_UNSUPPORTED = -1010;
067    int MEDIA_ERROR_TIMED_OUT = -110;
068
069    void setDisplay(SurfaceHolder sh);
070
071    void setDataSource(Context context, Uri uri)
072            throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
073
074    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
075    void setDataSource(Context context, Uri uri, Map<String, String> headers)
076            throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
077
078    void setDataSource(FileDescriptor fd) throws IOException, IllegalArgumentException, IllegalStateException;
079
080    void setDataSource(String path)
081            throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
082
083    String getDataSource();
084
085    void prepareAsync() throws IllegalStateException;
086
087    void start() throws IllegalStateException;
088
089    void stop() throws IllegalStateException;
090
091    void pause() throws IllegalStateException;
092
093    void setScreenOnWhilePlaying(boolean screenOn);
094
095    int getVideoWidth();
096
097    int getVideoHeight();
098
099    boolean isPlaying();
100
101    void seekTo(long msec) throws IllegalStateException;
102
103    long getCurrentPosition();
104
105    long getDuration();
106
107    void release();
108
109    void reset();
110
111    void setVolume(float leftVolume, float rightVolume);
112
113    int getAudioSessionId();
114
115    MediaInfo getMediaInfo();
116
117    @SuppressWarnings("EmptyMethod")
118    @Deprecated
119    void setLogEnabled(boolean enable);
120
121    @Deprecated
122    boolean isPlayable();
123
124    void setOnPreparedListener(OnPreparedListener listener);
125
126    void setOnCompletionListener(OnCompletionListener listener);
127
128    void setOnBufferingUpdateListener(OnBufferingUpdateListener listener);
129
130    void setOnSeekCompleteListener(OnSeekCompleteListener listener);
131
132    void setOnVideoSizeChangedListener(OnVideoSizeChangedListener listener);
133
134    void setOnErrorListener(OnErrorListener listener);
135
136    void setOnInfoListener(OnInfoListener listener);
137
138    void setOnTimedTextListener(OnTimedTextListener listener);
139
140    void setOnMetadataListener(OnMetadataListener listener);
141
142    /*--------------------
143     * Listeners
144     */
145    interface OnPreparedListener {
146        void onPrepared(IMediaPlayer mp);
147    }
148
149    interface OnCompletionListener {
150        void onCompletion(IMediaPlayer mp);
151    }
152
153    interface OnBufferingUpdateListener {
154        void onBufferingUpdate(IMediaPlayer mp, int percent);
155    }
156
157    interface OnSeekCompleteListener {
158        void onSeekComplete(IMediaPlayer mp);
159    }
160
161    interface OnVideoSizeChangedListener {
162        void onVideoSizeChanged(IMediaPlayer mp, int width, int height, int sar_num, int sar_den);
163    }
164
165    interface OnErrorListener {
166        boolean onError(IMediaPlayer mp, int what, int extra);
167    }
168
169    interface OnInfoListener {
170        boolean onInfo(IMediaPlayer mp, int what, int extra);
171    }
172
173    interface OnTimedTextListener {
174        void onTimedText(IMediaPlayer mp, BDTimedText text);
175    }
176
177    interface OnMetadataListener {
178        void onMetadata(IMediaPlayer mp, Bundle meta);
179    }
180
181    /*--------------------
182     * Optional
183     */
184    void setAudioStreamType(int streamtype);
185
186    @Deprecated
187    void setKeepInBackground(boolean keepInBackground);
188
189    int getVideoSarNum();
190
191    int getVideoSarDen();
192
193    @Deprecated
194    void setWakeMode(Context context, int mode);
195
196    void setLooping(boolean looping);
197
198    boolean isLooping();
199
200    /*--------------------
201     * AndroidMediaPlayer: JELLY_BEAN
202     */
203    ITrackInfo[] getTrackInfo();
204
205    /*--------------------
206     * AndroidMediaPlayer: ICE_CREAM_SANDWICH:
207     */
208    void setSurface(Surface surface);
209
210    /*--------------------
211     * AndroidMediaPlayer: M:
212     */
213    void setDataSource(IMediaDataSource mediaDataSource);
214}