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
17package com.android.ex.variablespeed;
18
19import android.media.MediaPlayer;
20
21import java.util.concurrent.Callable;
22import java.util.concurrent.FutureTask;
23import java.util.concurrent.TimeUnit;
24
25/**
26 * Tests that MediaPlayerProxyTestCase contains reasonable tests with a real {@link MediaPlayer}.
27 */
28public class RealMediaPlayerTest extends MediaPlayerProxyTestCase {
29    @Override
30    public MediaPlayerProxy createTestMediaPlayer() throws Exception {
31        // We have to construct the MediaPlayer on the main thread (or at least on a thread with an
32        // associated looper) otherwise we don't get sent the messages when callbacks should be
33        // invoked. I've raised a bug for this: http://b/4602011.
34        Callable<MediaPlayer> callable = new Callable<MediaPlayer>() {
35            @Override
36            public MediaPlayer call() throws Exception {
37                return new MediaPlayer();
38            }
39        };
40        FutureTask<MediaPlayer> future = new FutureTask<MediaPlayer>(callable);
41        getInstrumentation().runOnMainSync(future);
42        return DynamicProxy.dynamicProxy(MediaPlayerProxy.class, future.get(1, TimeUnit.SECONDS));
43    }
44}
45