android_LocAVPlayer.cpp revision 2b06e20ae32388f6e1dfd088d9773c34e6b1cb45
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define USE_LOG SLAndroidLogLevel_Verbose
18
19#include "sles_allinclusive.h"
20#include <media/IMediaPlayerService.h>
21#include "android_LocAVPlayer.h"
22
23
24namespace android {
25
26//--------------------------------------------------------------------------------------------------
27LocAVPlayer::LocAVPlayer(AudioPlayback_Parameters* params, bool hasVideo) :
28        GenericMediaPlayer(params, hasVideo)
29{
30    SL_LOGD("LocAVPlayer::LocAVPlayer()");
31
32}
33
34
35LocAVPlayer::~LocAVPlayer() {
36    SL_LOGD("LocAVPlayer::~LocAVPlayer()");
37
38}
39
40
41//--------------------------------------------------
42// Event handlers
43void LocAVPlayer::onPrepare() {
44    SL_LOGD("LocAVPlayer::onPrepare()");
45    switch (mDataLocatorType) {
46    case kDataLocatorUri:
47        mPlayer = mMediaPlayerService->create(getpid(), mPlayerClient /*IMediaPlayerClient*/,
48                mDataLocator.uriRef /*url*/, NULL /*headers*/, mPlaybackParams.sessionId);
49        break;
50    case kDataLocatorFd:
51        mPlayer = mMediaPlayerService->create(getpid(), mPlayerClient /*IMediaPlayerClient*/,
52                mDataLocator.fdi.fd, mDataLocator.fdi.offset, mDataLocator.fdi.length,
53                mPlaybackParams.sessionId);
54        break;
55    case kDataLocatorNone:
56        SL_LOGE("no data locator for MediaPlayer object");
57        break;
58    default:
59        SL_LOGE("unsupported data locator %d for MediaPlayer object", mDataLocatorType);
60        break;
61    }
62    // blocks until mPlayer is prepared
63    GenericMediaPlayer::onPrepare();
64    SL_LOGD("LocAVPlayer::onPrepare() done");
65}
66
67} // namespace android
68