summaryrefslogtreecommitdiffstats
path: root/variablespeed/tests/src/com/android/ex/variablespeed/RealMediaPlayerTest.java
blob: 7f126717fd46548f0decb757cf18ea4f5f6b7df6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.ex.variablespeed;

import android.media.MediaPlayer;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * Tests that MediaPlayerProxyTestCase contains reasonable tests with a real {@link MediaPlayer}.
 */
public class RealMediaPlayerTest extends MediaPlayerProxyTestCase {
    @Override
    public MediaPlayerProxy createTestMediaPlayer() throws Exception {
        // We have to construct the MediaPlayer on the main thread (or at least on a thread with an
        // associated looper) otherwise we don't get sent the messages when callbacks should be
        // invoked. I've raised a bug for this: http://b/4602011.
        Callable<MediaPlayer> callable = new Callable<MediaPlayer>() {
            @Override
            public MediaPlayer call() throws Exception {
                return new MediaPlayer();
            }
        };
        FutureTask<MediaPlayer> future = new FutureTask<MediaPlayer>(callable);
        getInstrumentation().runOnMainSync(future);
        return DynamicProxy.dynamicProxy(MediaPlayerProxy.class, future.get(1, TimeUnit.SECONDS));
    }
}