summaryrefslogtreecommitdiffstats
path: root/tests/src/com/cyngn/audiofx/util/TestMediaPlayer.java
blob: a22f7d4292c1f386f64f258922ccc58a0e9a511a (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
package org.cyanogenmod.audiofx.util;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;

import org.cyanogenmod.audiofx.tests.R;

import static junit.framework.Assert.assertNotNull;

/**
 * Created by roman on 3/4/16.
 */
public class TestMediaPlayer extends MediaPlayer {

    public TestMediaPlayer() {
        setAudioStreamType(AudioManager.STREAM_MUSIC);
    }

    public TestMediaPlayer(Context testContext, int withResource) throws Exception {
        this();
        AssetFileDescriptor afd = testContext.getResources().openRawResourceFd(withResource);
        assertNotNull(afd);
        setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        afd.close();
        prepare();
    }

}