1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package com.android.mediaframeworktest.power; 18 19import com.android.mediaframeworktest.MediaFrameworkTest; 20import com.android.mediaframeworktest.MediaNames; 21import android.media.MediaPlayer; 22import android.os.Environment; 23import android.test.ActivityInstrumentationTestCase2; 24import android.util.Log; 25 26import java.io.File; 27 28/** 29 * Junit / Instrumentation test case for the power measurment the media player 30 */ 31public class MediaPlayerPowerTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> { 32 private String TAG = "MediaPlayerPowerTest"; 33 private String MP3_POWERTEST = 34 Environment.getExternalStorageDirectory().toString() + "/power_sample_mp3.mp3"; 35 private String MP3_STREAM = "http://75.17.48.204:10088/power_media/power_sample_mp3.mp3"; 36 private String OGG_STREAM = "http://75.17.48.204:10088/power_media/power_sample_ogg.mp3"; 37 private String AAC_STREAM = "http://75.17.48.204:10088/power_media/power_sample_aac.mp3"; 38 39 public MediaPlayerPowerTest() { 40 super("com.android.mediaframeworktest", MediaFrameworkTest.class); 41 } 42 43 protected void setUp() throws Exception { 44 getActivity(); 45 super.setUp(); 46 47 } 48 49 public void audioPlayback(String filePath) { 50 try { 51 MediaPlayer mp = new MediaPlayer(); 52 mp.setDataSource(filePath); 53 mp.prepare(); 54 mp.start(); 55 Thread.sleep(200000); 56 mp.stop(); 57 mp.release(); 58 } catch (Exception e) { 59 Log.v(TAG, e.toString()); 60 assertTrue("MP3 Playback", false); 61 } 62 } 63 64 // A very simple test case which start the audio player. 65 // Power measurment will be done in other application. 66 public void testPowerLocalMP3Playback() throws Exception { 67 audioPlayback(MP3_POWERTEST); 68 } 69 70 public void testPowerStreamMP3Playback() throws Exception { 71 audioPlayback(MP3_STREAM); 72 } 73 74 public void testPowerStreamOGGPlayback() throws Exception { 75 audioPlayback(OGG_STREAM); 76 } 77 78 public void testPowerStreamAACPlayback() throws Exception { 79 audioPlayback(AAC_STREAM); 80 } 81} 82