blob: d94c7c5bf3bc510b939cc0e3ca761de3c49ca5dd [file] [log] [blame]
Glenn Kasten99e53b82012-01-19 08:59:58 -08001/*
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08002**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18//#define LOG_NDEBUG 0
19#define LOG_TAG "MediaPlayer"
20#include <utils/Log.h>
21
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <unistd.h>
25#include <fcntl.h>
26
Mathias Agopian75624082009-05-19 19:08:10 -070027#include <binder/IServiceManager.h>
28#include <binder/IPCThreadState.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080029
Mathias Agopianb1e7cd12013-02-14 17:11:27 -080030#include <gui/Surface.h>
Jamie Gennis61c7ef52011-07-13 12:59:34 -070031
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080032#include <media/mediaplayer.h>
Glenn Kastena3f1fa32012-01-18 14:54:46 -080033#include <media/AudioSystem.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080034
Mathias Agopian75624082009-05-19 19:08:10 -070035#include <binder/MemoryBase.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080036
Andreas Huber2db84552010-01-28 11:19:57 -080037#include <utils/KeyedVector.h>
38#include <utils/String8.h>
39
Dima Zavin64760242011-05-11 14:15:23 -070040#include <system/audio.h>
Jamie Gennis61c7ef52011-07-13 12:59:34 -070041#include <system/window.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070042
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080043namespace android {
44
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080045MediaPlayer::MediaPlayer()
46{
Steve Block3856b092011-10-20 11:56:00 +010047 ALOGV("constructor");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080048 mListener = NULL;
49 mCookie = NULL;
Dima Zavinfce7a472011-04-19 22:30:36 -070050 mStreamType = AUDIO_STREAM_MUSIC;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080051 mCurrentPosition = -1;
52 mSeekPosition = -1;
53 mCurrentState = MEDIA_PLAYER_IDLE;
54 mPrepareSync = false;
55 mPrepareStatus = NO_ERROR;
56 mLoop = false;
57 mLeftVolume = mRightVolume = 1.0;
58 mVideoWidth = mVideoHeight = 0;
Jason Sams1af452f2009-03-24 18:45:22 -070059 mLockThreadId = 0;
Eric Laurenta514bdb2010-06-21 09:27:30 -070060 mAudioSessionId = AudioSystem::newAudioSessionId();
Marco Nelissend457c972014-02-11 08:47:07 -080061 AudioSystem::acquireAudioSessionId(mAudioSessionId, -1);
Eric Laurent8c563ed2010-10-07 18:23:03 -070062 mSendLevel = 0;
John Grossmanc795b642012-02-22 15:38:35 -080063 mRetransmitEndpointValid = false;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080064}
65
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080066MediaPlayer::~MediaPlayer()
67{
Steve Block3856b092011-10-20 11:56:00 +010068 ALOGV("destructor");
Marco Nelissend457c972014-02-11 08:47:07 -080069 AudioSystem::releaseAudioSessionId(mAudioSessionId, -1);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080070 disconnect();
71 IPCThreadState::self()->flushCommands();
72}
73
74void MediaPlayer::disconnect()
75{
Steve Block3856b092011-10-20 11:56:00 +010076 ALOGV("disconnect");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080077 sp<IMediaPlayer> p;
78 {
79 Mutex::Autolock _l(mLock);
80 p = mPlayer;
81 mPlayer.clear();
82 }
83
84 if (p != 0) {
85 p->disconnect();
86 }
87}
88
89// always call with lock held
90void MediaPlayer::clear_l()
91{
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080092 mCurrentPosition = -1;
93 mSeekPosition = -1;
94 mVideoWidth = mVideoHeight = 0;
John Grossmanc795b642012-02-22 15:38:35 -080095 mRetransmitEndpointValid = false;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080096}
97
98status_t MediaPlayer::setListener(const sp<MediaPlayerListener>& listener)
99{
Steve Block3856b092011-10-20 11:56:00 +0100100 ALOGV("setListener");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800101 Mutex::Autolock _l(mLock);
102 mListener = listener;
103 return NO_ERROR;
104}
105
106
Dave Burked681bbb2011-08-30 14:39:17 +0100107status_t MediaPlayer::attachNewPlayer(const sp<IMediaPlayer>& player)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800108{
109 status_t err = UNKNOWN_ERROR;
110 sp<IMediaPlayer> p;
111 { // scope for the lock
112 Mutex::Autolock _l(mLock);
113
Marco Nelissen83ff1432010-03-10 10:53:16 -0800114 if ( !( (mCurrentState & MEDIA_PLAYER_IDLE) ||
115 (mCurrentState == MEDIA_PLAYER_STATE_ERROR ) ) ) {
Steve Block29357bc2012-01-06 19:20:56 +0000116 ALOGE("attachNewPlayer called in state %d", mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800117 return INVALID_OPERATION;
118 }
119
120 clear_l();
121 p = mPlayer;
122 mPlayer = player;
123 if (player != 0) {
124 mCurrentState = MEDIA_PLAYER_INITIALIZED;
125 err = NO_ERROR;
126 } else {
Masaki Muranakaf65fa172013-06-06 09:36:34 +0000127 ALOGE("Unable to create media player");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800128 }
129 }
130
131 if (p != 0) {
132 p->disconnect();
133 }
134
135 return err;
136}
137
Andreas Huber2db84552010-01-28 11:19:57 -0800138status_t MediaPlayer::setDataSource(
Andreas Huber1b86fe02014-01-29 11:13:26 -0800139 const sp<IMediaHTTPService> &httpService,
Andreas Huber2db84552010-01-28 11:19:57 -0800140 const char *url, const KeyedVector<String8, String8> *headers)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800141{
Steve Block3856b092011-10-20 11:56:00 +0100142 ALOGV("setDataSource(%s)", url);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800143 status_t err = BAD_VALUE;
144 if (url != NULL) {
145 const sp<IMediaPlayerService>& service(getMediaPlayerService());
146 if (service != 0) {
Glenn Kastenf37971f2012-02-03 11:06:53 -0800147 sp<IMediaPlayer> player(service->create(this, mAudioSessionId));
John Grossmanc795b642012-02-22 15:38:35 -0800148 if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
Andreas Huber1b86fe02014-01-29 11:13:26 -0800149 (NO_ERROR != player->setDataSource(httpService, url, headers))) {
Dave Burke06620672011-09-06 20:39:47 +0100150 player.clear();
Dave Burked681bbb2011-08-30 14:39:17 +0100151 }
Dave Burke06620672011-09-06 20:39:47 +0100152 err = attachNewPlayer(player);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800153 }
154 }
155 return err;
156}
157
158status_t MediaPlayer::setDataSource(int fd, int64_t offset, int64_t length)
159{
Steve Block3856b092011-10-20 11:56:00 +0100160 ALOGV("setDataSource(%d, %lld, %lld)", fd, offset, length);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800161 status_t err = UNKNOWN_ERROR;
162 const sp<IMediaPlayerService>& service(getMediaPlayerService());
163 if (service != 0) {
Glenn Kastenf37971f2012-02-03 11:06:53 -0800164 sp<IMediaPlayer> player(service->create(this, mAudioSessionId));
John Grossmanc795b642012-02-22 15:38:35 -0800165 if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
166 (NO_ERROR != player->setDataSource(fd, offset, length))) {
Dave Burke06620672011-09-06 20:39:47 +0100167 player.clear();
Dave Burked681bbb2011-08-30 14:39:17 +0100168 }
Dave Burke06620672011-09-06 20:39:47 +0100169 err = attachNewPlayer(player);
Dave Burked681bbb2011-08-30 14:39:17 +0100170 }
171 return err;
172}
173
174status_t MediaPlayer::setDataSource(const sp<IStreamSource> &source)
175{
Steve Block3856b092011-10-20 11:56:00 +0100176 ALOGV("setDataSource");
Dave Burked681bbb2011-08-30 14:39:17 +0100177 status_t err = UNKNOWN_ERROR;
178 const sp<IMediaPlayerService>& service(getMediaPlayerService());
179 if (service != 0) {
Glenn Kastenf37971f2012-02-03 11:06:53 -0800180 sp<IMediaPlayer> player(service->create(this, mAudioSessionId));
John Grossmanc795b642012-02-22 15:38:35 -0800181 if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
182 (NO_ERROR != player->setDataSource(source))) {
Dave Burke06620672011-09-06 20:39:47 +0100183 player.clear();
Dave Burked681bbb2011-08-30 14:39:17 +0100184 }
Dave Burke06620672011-09-06 20:39:47 +0100185 err = attachNewPlayer(player);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800186 }
187 return err;
188}
189
Nicolas Catania1d187f12009-05-12 23:25:55 -0700190status_t MediaPlayer::invoke(const Parcel& request, Parcel *reply)
191{
192 Mutex::Autolock _l(mLock);
Nicolas Catania40234932010-03-10 10:41:04 -0800193 const bool hasBeenInitialized =
194 (mCurrentState != MEDIA_PLAYER_STATE_ERROR) &&
195 ((mCurrentState & MEDIA_PLAYER_IDLE) != MEDIA_PLAYER_IDLE);
196 if ((mPlayer != NULL) && hasBeenInitialized) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700197 ALOGV("invoke %d", request.dataSize());
198 return mPlayer->invoke(request, reply);
Nicolas Catania1d187f12009-05-12 23:25:55 -0700199 }
Steve Block29357bc2012-01-06 19:20:56 +0000200 ALOGE("invoke failed: wrong state %X", mCurrentState);
Nicolas Catania1d187f12009-05-12 23:25:55 -0700201 return INVALID_OPERATION;
202}
203
Nicolas Cataniaa7e0e8b2009-07-08 08:57:42 -0700204status_t MediaPlayer::setMetadataFilter(const Parcel& filter)
205{
Steve Blockb8a80522011-12-20 16:23:08 +0000206 ALOGD("setMetadataFilter");
Nicolas Catania8e1b6cc2009-07-09 09:21:33 -0700207 Mutex::Autolock lock(mLock);
208 if (mPlayer == NULL) {
Nicolas Cataniaa7e0e8b2009-07-08 08:57:42 -0700209 return NO_INIT;
210 }
211 return mPlayer->setMetadataFilter(filter);
212}
Nicolas Catania1d187f12009-05-12 23:25:55 -0700213
Nicolas Catania8e1b6cc2009-07-09 09:21:33 -0700214status_t MediaPlayer::getMetadata(bool update_only, bool apply_filter, Parcel *metadata)
215{
Steve Blockb8a80522011-12-20 16:23:08 +0000216 ALOGD("getMetadata");
Nicolas Catania8e1b6cc2009-07-09 09:21:33 -0700217 Mutex::Autolock lock(mLock);
218 if (mPlayer == NULL) {
219 return NO_INIT;
220 }
221 return mPlayer->getMetadata(update_only, apply_filter, metadata);
222}
223
Glenn Kasten11731182011-02-08 17:26:17 -0800224status_t MediaPlayer::setVideoSurfaceTexture(
Andy McFadden484566c2012-12-18 09:46:54 -0800225 const sp<IGraphicBufferProducer>& bufferProducer)
Glenn Kasten11731182011-02-08 17:26:17 -0800226{
Steve Block3856b092011-10-20 11:56:00 +0100227 ALOGV("setVideoSurfaceTexture");
Glenn Kasten11731182011-02-08 17:26:17 -0800228 Mutex::Autolock _l(mLock);
229 if (mPlayer == 0) return NO_INIT;
Andy McFadden484566c2012-12-18 09:46:54 -0800230 return mPlayer->setVideoSurfaceTexture(bufferProducer);
Glenn Kasten11731182011-02-08 17:26:17 -0800231}
232
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800233// must call with lock held
234status_t MediaPlayer::prepareAsync_l()
235{
236 if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_INITIALIZED | MEDIA_PLAYER_STOPPED) ) ) {
237 mPlayer->setAudioStreamType(mStreamType);
238 mCurrentState = MEDIA_PLAYER_PREPARING;
239 return mPlayer->prepareAsync();
240 }
Steve Block29357bc2012-01-06 19:20:56 +0000241 ALOGE("prepareAsync called in state %d", mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800242 return INVALID_OPERATION;
243}
244
The Android Open Source Project65e731f2009-03-11 12:11:56 -0700245// TODO: In case of error, prepareAsync provides the caller with 2 error codes,
246// one defined in the Android framework and one provided by the implementation
247// that generated the error. The sync version of prepare returns only 1 error
248// code.
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800249status_t MediaPlayer::prepare()
250{
Steve Block3856b092011-10-20 11:56:00 +0100251 ALOGV("prepare");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800252 Mutex::Autolock _l(mLock);
Jason Sams1af452f2009-03-24 18:45:22 -0700253 mLockThreadId = getThreadId();
254 if (mPrepareSync) {
255 mLockThreadId = 0;
256 return -EALREADY;
257 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800258 mPrepareSync = true;
259 status_t ret = prepareAsync_l();
Jason Sams1af452f2009-03-24 18:45:22 -0700260 if (ret != NO_ERROR) {
261 mLockThreadId = 0;
262 return ret;
263 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800264
265 if (mPrepareSync) {
266 mSignal.wait(mLock); // wait for prepare done
267 mPrepareSync = false;
268 }
Steve Block3856b092011-10-20 11:56:00 +0100269 ALOGV("prepare complete - status=%d", mPrepareStatus);
Jason Sams1af452f2009-03-24 18:45:22 -0700270 mLockThreadId = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800271 return mPrepareStatus;
272}
273
274status_t MediaPlayer::prepareAsync()
275{
Steve Block3856b092011-10-20 11:56:00 +0100276 ALOGV("prepareAsync");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800277 Mutex::Autolock _l(mLock);
278 return prepareAsync_l();
279}
280
281status_t MediaPlayer::start()
282{
Steve Block3856b092011-10-20 11:56:00 +0100283 ALOGV("start");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800284 Mutex::Autolock _l(mLock);
285 if (mCurrentState & MEDIA_PLAYER_STARTED)
286 return NO_ERROR;
287 if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_PREPARED |
288 MEDIA_PLAYER_PLAYBACK_COMPLETE | MEDIA_PLAYER_PAUSED ) ) ) {
289 mPlayer->setLooping(mLoop);
290 mPlayer->setVolume(mLeftVolume, mRightVolume);
Eric Laurent2beeb502010-07-16 07:43:46 -0700291 mPlayer->setAuxEffectSendLevel(mSendLevel);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800292 mCurrentState = MEDIA_PLAYER_STARTED;
293 status_t ret = mPlayer->start();
294 if (ret != NO_ERROR) {
295 mCurrentState = MEDIA_PLAYER_STATE_ERROR;
296 } else {
297 if (mCurrentState == MEDIA_PLAYER_PLAYBACK_COMPLETE) {
Steve Block3856b092011-10-20 11:56:00 +0100298 ALOGV("playback completed immediately following start()");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800299 }
300 }
301 return ret;
302 }
Steve Block29357bc2012-01-06 19:20:56 +0000303 ALOGE("start called in state %d", mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800304 return INVALID_OPERATION;
305}
306
307status_t MediaPlayer::stop()
308{
Steve Block3856b092011-10-20 11:56:00 +0100309 ALOGV("stop");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800310 Mutex::Autolock _l(mLock);
311 if (mCurrentState & MEDIA_PLAYER_STOPPED) return NO_ERROR;
312 if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED |
313 MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) ) {
314 status_t ret = mPlayer->stop();
315 if (ret != NO_ERROR) {
316 mCurrentState = MEDIA_PLAYER_STATE_ERROR;
317 } else {
318 mCurrentState = MEDIA_PLAYER_STOPPED;
319 }
320 return ret;
321 }
Steve Block29357bc2012-01-06 19:20:56 +0000322 ALOGE("stop called in state %d", mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800323 return INVALID_OPERATION;
324}
325
326status_t MediaPlayer::pause()
327{
Steve Block3856b092011-10-20 11:56:00 +0100328 ALOGV("pause");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800329 Mutex::Autolock _l(mLock);
Marco Nelissen698f4762010-02-26 13:16:23 -0800330 if (mCurrentState & (MEDIA_PLAYER_PAUSED|MEDIA_PLAYER_PLAYBACK_COMPLETE))
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800331 return NO_ERROR;
332 if ((mPlayer != 0) && (mCurrentState & MEDIA_PLAYER_STARTED)) {
333 status_t ret = mPlayer->pause();
334 if (ret != NO_ERROR) {
335 mCurrentState = MEDIA_PLAYER_STATE_ERROR;
336 } else {
337 mCurrentState = MEDIA_PLAYER_PAUSED;
338 }
339 return ret;
340 }
Steve Block29357bc2012-01-06 19:20:56 +0000341 ALOGE("pause called in state %d", mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800342 return INVALID_OPERATION;
343}
344
345bool MediaPlayer::isPlaying()
346{
347 Mutex::Autolock _l(mLock);
348 if (mPlayer != 0) {
349 bool temp = false;
350 mPlayer->isPlaying(&temp);
Steve Block3856b092011-10-20 11:56:00 +0100351 ALOGV("isPlaying: %d", temp);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800352 if ((mCurrentState & MEDIA_PLAYER_STARTED) && ! temp) {
Steve Block29357bc2012-01-06 19:20:56 +0000353 ALOGE("internal/external state mismatch corrected");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800354 mCurrentState = MEDIA_PLAYER_PAUSED;
355 }
356 return temp;
357 }
Steve Block3856b092011-10-20 11:56:00 +0100358 ALOGV("isPlaying: no active player");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800359 return false;
360}
361
362status_t MediaPlayer::getVideoWidth(int *w)
363{
Steve Block3856b092011-10-20 11:56:00 +0100364 ALOGV("getVideoWidth");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800365 Mutex::Autolock _l(mLock);
366 if (mPlayer == 0) return INVALID_OPERATION;
367 *w = mVideoWidth;
368 return NO_ERROR;
369}
370
371status_t MediaPlayer::getVideoHeight(int *h)
372{
Steve Block3856b092011-10-20 11:56:00 +0100373 ALOGV("getVideoHeight");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800374 Mutex::Autolock _l(mLock);
375 if (mPlayer == 0) return INVALID_OPERATION;
376 *h = mVideoHeight;
377 return NO_ERROR;
378}
379
380status_t MediaPlayer::getCurrentPosition(int *msec)
381{
Steve Block3856b092011-10-20 11:56:00 +0100382 ALOGV("getCurrentPosition");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800383 Mutex::Autolock _l(mLock);
384 if (mPlayer != 0) {
385 if (mCurrentPosition >= 0) {
Steve Block3856b092011-10-20 11:56:00 +0100386 ALOGV("Using cached seek position: %d", mCurrentPosition);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800387 *msec = mCurrentPosition;
388 return NO_ERROR;
389 }
390 return mPlayer->getCurrentPosition(msec);
391 }
392 return INVALID_OPERATION;
393}
394
395status_t MediaPlayer::getDuration_l(int *msec)
396{
Andreas Hubera4c5bc02012-11-27 15:02:53 -0800397 ALOGV("getDuration_l");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800398 bool isValidState = (mCurrentState & (MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_STOPPED | MEDIA_PLAYER_PLAYBACK_COMPLETE));
399 if (mPlayer != 0 && isValidState) {
Andreas Hubera4c5bc02012-11-27 15:02:53 -0800400 int durationMs;
401 status_t ret = mPlayer->getDuration(&durationMs);
Andreas Huber20702542013-04-11 11:07:55 -0700402
403 if (ret != OK) {
404 // Do not enter error state just because no duration was available.
405 durationMs = -1;
406 ret = OK;
407 }
408
Andreas Hubera4c5bc02012-11-27 15:02:53 -0800409 if (msec) {
410 *msec = durationMs;
411 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800412 return ret;
413 }
Steve Block29357bc2012-01-06 19:20:56 +0000414 ALOGE("Attempt to call getDuration without a valid mediaplayer");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800415 return INVALID_OPERATION;
416}
417
418status_t MediaPlayer::getDuration(int *msec)
419{
420 Mutex::Autolock _l(mLock);
421 return getDuration_l(msec);
422}
423
424status_t MediaPlayer::seekTo_l(int msec)
425{
Steve Block3856b092011-10-20 11:56:00 +0100426 ALOGV("seekTo %d", msec);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800427 if ((mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE) ) ) {
428 if ( msec < 0 ) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000429 ALOGW("Attempt to seek to invalid position: %d", msec);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800430 msec = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800431 }
Andreas Hubera4c5bc02012-11-27 15:02:53 -0800432
433 int durationMs;
434 status_t err = mPlayer->getDuration(&durationMs);
435
436 if (err != OK) {
437 ALOGW("Stream has no duration and is therefore not seekable.");
438 return err;
439 }
440
441 if (msec > durationMs) {
442 ALOGW("Attempt to seek to past end of file: request = %d, "
443 "durationMs = %d",
444 msec,
445 durationMs);
446
447 msec = durationMs;
448 }
449
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800450 // cache duration
451 mCurrentPosition = msec;
452 if (mSeekPosition < 0) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800453 mSeekPosition = msec;
454 return mPlayer->seekTo(msec);
455 }
456 else {
Steve Block3856b092011-10-20 11:56:00 +0100457 ALOGV("Seek in progress - queue up seekTo[%d]", msec);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800458 return NO_ERROR;
459 }
460 }
Steve Block29357bc2012-01-06 19:20:56 +0000461 ALOGE("Attempt to perform seekTo in wrong state: mPlayer=%p, mCurrentState=%u", mPlayer.get(), mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800462 return INVALID_OPERATION;
463}
464
465status_t MediaPlayer::seekTo(int msec)
466{
Andreas Huber5cb07aa2009-03-24 20:48:51 -0700467 mLockThreadId = getThreadId();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800468 Mutex::Autolock _l(mLock);
Andreas Huber5cb07aa2009-03-24 20:48:51 -0700469 status_t result = seekTo_l(msec);
470 mLockThreadId = 0;
471
472 return result;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800473}
474
Jamie Gennis61c7ef52011-07-13 12:59:34 -0700475status_t MediaPlayer::reset_l()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800476{
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800477 mLoop = false;
478 if (mCurrentState == MEDIA_PLAYER_IDLE) return NO_ERROR;
479 mPrepareSync = false;
480 if (mPlayer != 0) {
481 status_t ret = mPlayer->reset();
482 if (ret != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000483 ALOGE("reset() failed with return code (%d)", ret);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800484 mCurrentState = MEDIA_PLAYER_STATE_ERROR;
485 } else {
486 mCurrentState = MEDIA_PLAYER_IDLE;
487 }
James Donga1680bc2010-11-18 12:23:58 -0800488 // setDataSource has to be called again to create a
489 // new mediaplayer.
490 mPlayer = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800491 return ret;
492 }
493 clear_l();
494 return NO_ERROR;
495}
496
John Grossmanc795b642012-02-22 15:38:35 -0800497status_t MediaPlayer::doSetRetransmitEndpoint(const sp<IMediaPlayer>& player) {
498 Mutex::Autolock _l(mLock);
499
500 if (player == NULL) {
501 return UNKNOWN_ERROR;
502 }
503
504 if (mRetransmitEndpointValid) {
505 return player->setRetransmitEndpoint(&mRetransmitEndpoint);
506 }
507
508 return OK;
509}
510
Jamie Gennis61c7ef52011-07-13 12:59:34 -0700511status_t MediaPlayer::reset()
512{
Steve Block3856b092011-10-20 11:56:00 +0100513 ALOGV("reset");
Jamie Gennis61c7ef52011-07-13 12:59:34 -0700514 Mutex::Autolock _l(mLock);
515 return reset_l();
516}
517
Glenn Kastenfff6d712012-01-12 16:38:12 -0800518status_t MediaPlayer::setAudioStreamType(audio_stream_type_t type)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800519{
Steve Block3856b092011-10-20 11:56:00 +0100520 ALOGV("MediaPlayer::setAudioStreamType");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800521 Mutex::Autolock _l(mLock);
522 if (mStreamType == type) return NO_ERROR;
523 if (mCurrentState & ( MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED |
524 MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) {
525 // Can't change the stream type after prepare
Steve Block29357bc2012-01-06 19:20:56 +0000526 ALOGE("setAudioStream called in state %d", mCurrentState);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800527 return INVALID_OPERATION;
528 }
529 // cache
530 mStreamType = type;
531 return OK;
532}
533
534status_t MediaPlayer::setLooping(int loop)
535{
Steve Block3856b092011-10-20 11:56:00 +0100536 ALOGV("MediaPlayer::setLooping");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800537 Mutex::Autolock _l(mLock);
538 mLoop = (loop != 0);
539 if (mPlayer != 0) {
540 return mPlayer->setLooping(loop);
541 }
542 return OK;
543}
544
545bool MediaPlayer::isLooping() {
Steve Block3856b092011-10-20 11:56:00 +0100546 ALOGV("isLooping");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800547 Mutex::Autolock _l(mLock);
548 if (mPlayer != 0) {
549 return mLoop;
550 }
Steve Block3856b092011-10-20 11:56:00 +0100551 ALOGV("isLooping: no active player");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800552 return false;
553}
554
555status_t MediaPlayer::setVolume(float leftVolume, float rightVolume)
556{
Steve Block3856b092011-10-20 11:56:00 +0100557 ALOGV("MediaPlayer::setVolume(%f, %f)", leftVolume, rightVolume);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800558 Mutex::Autolock _l(mLock);
559 mLeftVolume = leftVolume;
560 mRightVolume = rightVolume;
561 if (mPlayer != 0) {
562 return mPlayer->setVolume(leftVolume, rightVolume);
563 }
564 return OK;
565}
566
Eric Laurenta514bdb2010-06-21 09:27:30 -0700567status_t MediaPlayer::setAudioSessionId(int sessionId)
568{
Steve Block3856b092011-10-20 11:56:00 +0100569 ALOGV("MediaPlayer::setAudioSessionId(%d)", sessionId);
Eric Laurenta514bdb2010-06-21 09:27:30 -0700570 Mutex::Autolock _l(mLock);
571 if (!(mCurrentState & MEDIA_PLAYER_IDLE)) {
Steve Block29357bc2012-01-06 19:20:56 +0000572 ALOGE("setAudioSessionId called in state %d", mCurrentState);
Eric Laurenta514bdb2010-06-21 09:27:30 -0700573 return INVALID_OPERATION;
574 }
575 if (sessionId < 0) {
576 return BAD_VALUE;
577 }
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700578 if (sessionId != mAudioSessionId) {
Marco Nelissend457c972014-02-11 08:47:07 -0800579 AudioSystem::acquireAudioSessionId(sessionId, -1);
580 AudioSystem::releaseAudioSessionId(mAudioSessionId, -1);
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700581 mAudioSessionId = sessionId;
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700582 }
Eric Laurenta514bdb2010-06-21 09:27:30 -0700583 return NO_ERROR;
584}
585
586int MediaPlayer::getAudioSessionId()
587{
588 Mutex::Autolock _l(mLock);
589 return mAudioSessionId;
590}
591
Eric Laurent2beeb502010-07-16 07:43:46 -0700592status_t MediaPlayer::setAuxEffectSendLevel(float level)
593{
Steve Block3856b092011-10-20 11:56:00 +0100594 ALOGV("MediaPlayer::setAuxEffectSendLevel(%f)", level);
Eric Laurent2beeb502010-07-16 07:43:46 -0700595 Mutex::Autolock _l(mLock);
596 mSendLevel = level;
597 if (mPlayer != 0) {
598 return mPlayer->setAuxEffectSendLevel(level);
599 }
600 return OK;
601}
602
603status_t MediaPlayer::attachAuxEffect(int effectId)
604{
Steve Block3856b092011-10-20 11:56:00 +0100605 ALOGV("MediaPlayer::attachAuxEffect(%d)", effectId);
Eric Laurent2beeb502010-07-16 07:43:46 -0700606 Mutex::Autolock _l(mLock);
607 if (mPlayer == 0 ||
608 (mCurrentState & MEDIA_PLAYER_IDLE) ||
609 (mCurrentState == MEDIA_PLAYER_STATE_ERROR )) {
Steve Block29357bc2012-01-06 19:20:56 +0000610 ALOGE("attachAuxEffect called in state %d", mCurrentState);
Eric Laurent2beeb502010-07-16 07:43:46 -0700611 return INVALID_OPERATION;
612 }
613
614 return mPlayer->attachAuxEffect(effectId);
615}
616
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700617status_t MediaPlayer::setParameter(int key, const Parcel& request)
618{
Steve Block3856b092011-10-20 11:56:00 +0100619 ALOGV("MediaPlayer::setParameter(%d)", key);
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700620 Mutex::Autolock _l(mLock);
621 if (mPlayer != NULL) {
622 return mPlayer->setParameter(key, request);
623 }
Steve Block3856b092011-10-20 11:56:00 +0100624 ALOGV("setParameter: no active player");
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700625 return INVALID_OPERATION;
626}
627
628status_t MediaPlayer::getParameter(int key, Parcel *reply)
629{
Steve Block3856b092011-10-20 11:56:00 +0100630 ALOGV("MediaPlayer::getParameter(%d)", key);
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700631 Mutex::Autolock _l(mLock);
632 if (mPlayer != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700633 return mPlayer->getParameter(key, reply);
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700634 }
Steve Block3856b092011-10-20 11:56:00 +0100635 ALOGV("getParameter: no active player");
Gloria Wang4f9e47f2011-04-25 17:28:22 -0700636 return INVALID_OPERATION;
637}
638
John Grossmanc795b642012-02-22 15:38:35 -0800639status_t MediaPlayer::setRetransmitEndpoint(const char* addrString,
640 uint16_t port) {
641 ALOGV("MediaPlayer::setRetransmitEndpoint(%s:%hu)",
642 addrString ? addrString : "(null)", port);
643
644 Mutex::Autolock _l(mLock);
645 if ((mPlayer != NULL) || (mCurrentState != MEDIA_PLAYER_IDLE))
646 return INVALID_OPERATION;
647
648 if (NULL == addrString) {
649 mRetransmitEndpointValid = false;
650 return OK;
651 }
652
653 struct in_addr saddr;
654 if(!inet_aton(addrString, &saddr)) {
655 return BAD_VALUE;
656 }
657
Glenn Kastenbe08f6a2013-12-19 09:09:33 -0800658 memset(&mRetransmitEndpoint, 0, sizeof(mRetransmitEndpoint));
John Grossmanc795b642012-02-22 15:38:35 -0800659 mRetransmitEndpoint.sin_family = AF_INET;
660 mRetransmitEndpoint.sin_addr = saddr;
661 mRetransmitEndpoint.sin_port = htons(port);
662 mRetransmitEndpointValid = true;
663
664 return OK;
665}
666
Gloria Wangb483c472011-04-11 17:23:27 -0700667void MediaPlayer::notify(int msg, int ext1, int ext2, const Parcel *obj)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800668{
Steve Block3856b092011-10-20 11:56:00 +0100669 ALOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800670 bool send = true;
Jason Sams1af452f2009-03-24 18:45:22 -0700671 bool locked = false;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800672
673 // TODO: In the future, we might be on the same thread if the app is
674 // running in the same process as the media server. In that case,
675 // this will deadlock.
Nicolas Catania66095182009-06-11 16:33:49 -0700676 //
Jason Sams1af452f2009-03-24 18:45:22 -0700677 // The threadId hack below works around this for the care of prepare
Andreas Huber5cb07aa2009-03-24 20:48:51 -0700678 // and seekTo within the same process.
679 // FIXME: Remember, this is a hack, it's not even a hack that is applied
680 // consistently for all use-cases, this needs to be revisited.
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700681 if (mLockThreadId != getThreadId()) {
Jason Sams1af452f2009-03-24 18:45:22 -0700682 mLock.lock();
683 locked = true;
Nicolas Catania66095182009-06-11 16:33:49 -0700684 }
Jason Sams1af452f2009-03-24 18:45:22 -0700685
Eric Laurent3b268442010-08-03 07:49:49 -0700686 // Allows calls from JNI in idle state to notify errors
687 if (!(msg == MEDIA_ERROR && mCurrentState == MEDIA_PLAYER_IDLE) && mPlayer == 0) {
Steve Block3856b092011-10-20 11:56:00 +0100688 ALOGV("notify(%d, %d, %d) callback on disconnected mediaplayer", msg, ext1, ext2);
Jason Sams1af452f2009-03-24 18:45:22 -0700689 if (locked) mLock.unlock(); // release the lock when done.
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800690 return;
691 }
692
693 switch (msg) {
694 case MEDIA_NOP: // interface test message
695 break;
696 case MEDIA_PREPARED:
Steve Block3856b092011-10-20 11:56:00 +0100697 ALOGV("prepared");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800698 mCurrentState = MEDIA_PLAYER_PREPARED;
699 if (mPrepareSync) {
Steve Block3856b092011-10-20 11:56:00 +0100700 ALOGV("signal application thread");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800701 mPrepareSync = false;
702 mPrepareStatus = NO_ERROR;
703 mSignal.signal();
704 }
705 break;
706 case MEDIA_PLAYBACK_COMPLETE:
Steve Block3856b092011-10-20 11:56:00 +0100707 ALOGV("playback complete");
Marco Nelissen1c1503c2010-09-17 15:04:01 -0700708 if (mCurrentState == MEDIA_PLAYER_IDLE) {
Steve Block29357bc2012-01-06 19:20:56 +0000709 ALOGE("playback complete in idle state");
Marco Nelissen1c1503c2010-09-17 15:04:01 -0700710 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800711 if (!mLoop) {
712 mCurrentState = MEDIA_PLAYER_PLAYBACK_COMPLETE;
713 }
714 break;
715 case MEDIA_ERROR:
The Android Open Source Project65e731f2009-03-11 12:11:56 -0700716 // Always log errors.
717 // ext1: Media framework error code.
718 // ext2: Implementation dependant error code.
Steve Block29357bc2012-01-06 19:20:56 +0000719 ALOGE("error (%d, %d)", ext1, ext2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800720 mCurrentState = MEDIA_PLAYER_STATE_ERROR;
721 if (mPrepareSync)
722 {
Steve Block3856b092011-10-20 11:56:00 +0100723 ALOGV("signal application thread");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800724 mPrepareSync = false;
725 mPrepareStatus = ext1;
726 mSignal.signal();
727 send = false;
728 }
729 break;
The Android Open Source Project65e731f2009-03-11 12:11:56 -0700730 case MEDIA_INFO:
731 // ext1: Media framework error code.
732 // ext2: Implementation dependant error code.
Andreas Huber145e68f2011-01-11 15:05:28 -0800733 if (ext1 != MEDIA_INFO_VIDEO_TRACK_LAGGING) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000734 ALOGW("info/warning (%d, %d)", ext1, ext2);
Andreas Huber145e68f2011-01-11 15:05:28 -0800735 }
The Android Open Source Project65e731f2009-03-11 12:11:56 -0700736 break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800737 case MEDIA_SEEK_COMPLETE:
Steve Block3856b092011-10-20 11:56:00 +0100738 ALOGV("Received seek complete");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800739 if (mSeekPosition != mCurrentPosition) {
Steve Block3856b092011-10-20 11:56:00 +0100740 ALOGV("Executing queued seekTo(%d)", mSeekPosition);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800741 mSeekPosition = -1;
742 seekTo_l(mCurrentPosition);
743 }
744 else {
Steve Block3856b092011-10-20 11:56:00 +0100745 ALOGV("All seeks complete - return to regularly scheduled program");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800746 mCurrentPosition = mSeekPosition = -1;
747 }
748 break;
749 case MEDIA_BUFFERING_UPDATE:
Steve Block3856b092011-10-20 11:56:00 +0100750 ALOGV("buffering %d", ext1);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800751 break;
752 case MEDIA_SET_VIDEO_SIZE:
Steve Block3856b092011-10-20 11:56:00 +0100753 ALOGV("New video size %d x %d", ext1, ext2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800754 mVideoWidth = ext1;
755 mVideoHeight = ext2;
756 break;
Gloria Wangb483c472011-04-11 17:23:27 -0700757 case MEDIA_TIMED_TEXT:
Steve Block3856b092011-10-20 11:56:00 +0100758 ALOGV("Received timed text message");
Gloria Wangb483c472011-04-11 17:23:27 -0700759 break;
Chong Zhangdcb89b32013-08-06 09:44:47 -0700760 case MEDIA_SUBTITLE_DATA:
761 ALOGV("Received subtitle data message");
762 break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800763 default:
Steve Block3856b092011-10-20 11:56:00 +0100764 ALOGV("unrecognized message: (%d, %d, %d)", msg, ext1, ext2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800765 break;
766 }
767
768 sp<MediaPlayerListener> listener = mListener;
Jason Sams1af452f2009-03-24 18:45:22 -0700769 if (locked) mLock.unlock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800770
771 // this prevents re-entrant calls into client code
772 if ((listener != 0) && send) {
773 Mutex::Autolock _l(mNotifyLock);
Steve Block3856b092011-10-20 11:56:00 +0100774 ALOGV("callback application");
Gloria Wangb483c472011-04-11 17:23:27 -0700775 listener->notify(msg, ext1, ext2, obj);
Steve Block3856b092011-10-20 11:56:00 +0100776 ALOGV("back from callback");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800777 }
778}
779
Andreas Huber1b86fe02014-01-29 11:13:26 -0800780/*static*/ status_t MediaPlayer::decode(
781 const sp<IMediaHTTPService> &httpService,
782 const char* url,
783 uint32_t *pSampleRate,
784 int* pNumChannels,
785 audio_format_t* pFormat,
786 const sp<IMemoryHeap>& heap,
787 size_t *pSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800788{
Steve Block3856b092011-10-20 11:56:00 +0100789 ALOGV("decode(%s)", url);
Eric Laurent3d00aa62013-09-24 09:53:27 -0700790 status_t status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800791 const sp<IMediaPlayerService>& service = getMediaPlayerService();
792 if (service != 0) {
Andreas Huber1b86fe02014-01-29 11:13:26 -0800793 status = service->decode(httpService, url, pSampleRate, pNumChannels, pFormat, heap, pSize);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800794 } else {
Steve Block29357bc2012-01-06 19:20:56 +0000795 ALOGE("Unable to locate media service");
Eric Laurent3d00aa62013-09-24 09:53:27 -0700796 status = DEAD_OBJECT;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800797 }
Eric Laurent3d00aa62013-09-24 09:53:27 -0700798 return status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800799
800}
801
James Dongdd172fc2010-01-15 18:13:58 -0800802void MediaPlayer::died()
803{
Steve Block3856b092011-10-20 11:56:00 +0100804 ALOGV("died");
James Dongdd172fc2010-01-15 18:13:58 -0800805 notify(MEDIA_ERROR, MEDIA_ERROR_SERVER_DIED, 0);
806}
807
Eric Laurent3d00aa62013-09-24 09:53:27 -0700808/*static*/ status_t MediaPlayer::decode(int fd, int64_t offset, int64_t length,
809 uint32_t *pSampleRate, int* pNumChannels,
810 audio_format_t* pFormat,
811 const sp<IMemoryHeap>& heap, size_t *pSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800812{
Steve Block3856b092011-10-20 11:56:00 +0100813 ALOGV("decode(%d, %lld, %lld)", fd, offset, length);
Eric Laurent3d00aa62013-09-24 09:53:27 -0700814 status_t status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800815 const sp<IMediaPlayerService>& service = getMediaPlayerService();
816 if (service != 0) {
Eric Laurent3d00aa62013-09-24 09:53:27 -0700817 status = service->decode(fd, offset, length, pSampleRate,
818 pNumChannels, pFormat, heap, pSize);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800819 } else {
Steve Block29357bc2012-01-06 19:20:56 +0000820 ALOGE("Unable to locate media service");
Eric Laurent3d00aa62013-09-24 09:53:27 -0700821 status = DEAD_OBJECT;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800822 }
Eric Laurent3d00aa62013-09-24 09:53:27 -0700823 return status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800824
825}
826
Marco Nelissen6b74d672012-02-28 16:07:44 -0800827status_t MediaPlayer::setNextMediaPlayer(const sp<MediaPlayer>& next) {
828 if (mPlayer == NULL) {
829 return NO_INIT;
830 }
Marco Nelissenb13820f2013-08-05 12:22:43 -0700831
832 if (next != NULL && !(next->mCurrentState &
833 (MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE))) {
834 ALOGE("next player is not prepared");
835 return INVALID_OPERATION;
836 }
837
Marco Nelissen6b74d672012-02-28 16:07:44 -0800838 return mPlayer->setNextPlayer(next == NULL ? NULL : next->mPlayer);
839}
840
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800841}; // namespace android