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_ERROR_UNKNOWN = 1;
059    int MEDIA_ERROR_SERVER_DIED = 100;
060    int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200;
061    int MEDIA_ERROR_IO = -1004;
062    int MEDIA_ERROR_MALFORMED = -1007;
063    int MEDIA_ERROR_UNSUPPORTED = -1010;
064    int MEDIA_ERROR_TIMED_OUT = -110;
065
066    void setDisplay(SurfaceHolder sh);
067
068    void setDataSource(Context context, Uri uri)
069            throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
070
071    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
072    void setDataSource(Context context, Uri uri, Map<String, String> headers)
073            throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
074
075    void setDataSource(FileDescriptor fd) throws IOException, IllegalArgumentException, IllegalStateException;
076
077    void setDataSource(String path)
078            throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
079
080    String getDataSource();
081
082    void prepareAsync() throws IllegalStateException;
083
084    void start() throws IllegalStateException;
085
086    void stop() throws IllegalStateException;
087
088    void pause() throws IllegalStateException;
089
090    void setScreenOnWhilePlaying(boolean screenOn);
091
092    int getVideoWidth();
093
094    int getVideoHeight();
095
096    boolean isPlaying();
097
098    void seekTo(long msec) throws IllegalStateException;
099
100    long getCurrentPosition();
101
102    long getDuration();
103
104    void release();
105
106    void reset();
107
108    void setVolume(float leftVolume, float rightVolume);
109
110    int getAudioSessionId();
111
112    MediaInfo getMediaInfo();
113
114    @SuppressWarnings("EmptyMethod")
115    @Deprecated
116    void setLogEnabled(boolean enable);
117
118    @Deprecated
119    boolean isPlayable();
120
121    void setOnPreparedListener(OnPreparedListener listener);
122
123    void setOnCompletionListener(OnCompletionListener listener);
124
125    void setOnBufferingUpdateListener(OnBufferingUpdateListener listener);
126
127    void setOnSeekCompleteListener(OnSeekCompleteListener listener);
128
129    void setOnVideoSizeChangedListener(OnVideoSizeChangedListener listener);
130
131    void setOnErrorListener(OnErrorListener listener);
132
133    void setOnInfoListener(OnInfoListener listener);
134
135    void setOnTimedTextListener(OnTimedTextListener listener);
136
137    void setOnMetadataListener(OnMetadataListener listener);
138
139    /*--------------------
140     * Listeners
141     */
142    interface OnPreparedListener {
143        void onPrepared(IMediaPlayer mp);
144    }
145
146    interface OnCompletionListener {
147        void onCompletion(IMediaPlayer mp);
148    }
149
150    interface OnBufferingUpdateListener {
151        void onBufferingUpdate(IMediaPlayer mp, int percent);
152    }
153
154    interface OnSeekCompleteListener {
155        void onSeekComplete(IMediaPlayer mp);
156    }
157
158    interface OnVideoSizeChangedListener {
159        void onVideoSizeChanged(IMediaPlayer mp, int width, int height, int sar_num, int sar_den);
160    }
161
162    interface OnErrorListener {
163        boolean onError(IMediaPlayer mp, int what, int extra);
164    }
165
166    interface OnInfoListener {
167        boolean onInfo(IMediaPlayer mp, int what, int extra);
168    }
169
170    interface OnTimedTextListener {
171        void onTimedText(IMediaPlayer mp, BDTimedText text);
172    }
173
174    interface OnMetadataListener {
175        void onMetadata(IMediaPlayer mp, Bundle meta);
176    }
177
178    /*--------------------
179     * Optional
180     */
181    void setAudioStreamType(int streamtype);
182
183    @Deprecated
184    void setKeepInBackground(boolean keepInBackground);
185
186    int getVideoSarNum();
187
188    int getVideoSarDen();
189
190    @Deprecated
191    void setWakeMode(Context context, int mode);
192
193    void setLooping(boolean looping);
194
195    boolean isLooping();
196
197    /*--------------------
198     * AndroidMediaPlayer: JELLY_BEAN
199     */
200    ITrackInfo[] getTrackInfo();
201
202    /*--------------------
203     * AndroidMediaPlayer: ICE_CREAM_SANDWICH:
204     */
205    void setSurface(Surface surface);
206
207    /*--------------------
208     * AndroidMediaPlayer: M:
209     */
210    void setDataSource(IMediaDataSource mediaDataSource);
211}