1 /* 2 * Copyright (C) 2008 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 package com.android.mediaframeworktest.functional.mediaplayback; 18 19 import com.android.mediaframeworktest.MediaFrameworkTest; 20 import com.android.mediaframeworktest.MediaNames; 21 import com.android.mediaframeworktest.MediaProfileReader; 22 import com.android.mediaframeworktest.functional.CodecTest; 23 24 import android.content.Context; 25 import android.test.ActivityInstrumentationTestCase2; 26 import android.util.Log; 27 import android.test.suitebuilder.annotation.LargeTest; 28 import android.test.suitebuilder.annotation.MediumTest; 29 import android.test.suitebuilder.annotation.Suppress; 30 31 import java.io.File; 32 33 /** 34 * Junit / Instrumentation test case for the media player api 35 */ 36 public class MediaPlayerApiTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> { 37 private boolean duratoinWithinTolerence = false; 38 private String TAG = "MediaPlayerApiTest"; 39 private boolean isWMAEnable = false; 40 private boolean isWMVEnable = false; 41 42 Context mContext; 43 44 public MediaPlayerApiTest() { 45 super("com.android.mediaframeworktest", MediaFrameworkTest.class); 46 isWMAEnable = MediaProfileReader.getWMAEnable(); 47 isWMVEnable = MediaProfileReader.getWMVEnable(); 48 } 49 50 protected void setUp() throws Exception { 51 //Insert a 2 second before launching the test activity. This is 52 //the workaround for the race condition of requesting the updated surface. 53 Thread.sleep(2000); 54 getActivity(); 55 super.setUp(); 56 } 57 58 public boolean verifyDuration(int duration, int expectedDuration){ 59 if ((duration > expectedDuration * 1.1) || (duration < expectedDuration * 0.9)) 60 return false; 61 else 62 return true; 63 } 64 65 66 67 //Audio 68 //Wait for PV bugs for MP3 duration 69 @MediumTest 70 public void testMP3CBRGetDuration() throws Exception { 71 int duration = CodecTest.getDuration(MediaNames.MP3CBR); 72 duratoinWithinTolerence = verifyDuration(duration, MediaNames.MP3CBR_LENGTH); 73 assertTrue("MP3CBR getDuration", duratoinWithinTolerence); 74 } 75 76 @MediumTest 77 public void testMP3VBRGetDuration() throws Exception { 78 int duration = CodecTest.getDuration(MediaNames.MP3VBR); 79 Log.v(TAG, "getDuration"); 80 duratoinWithinTolerence = verifyDuration(duration, MediaNames.MP3VBR_LENGTH); 81 assertTrue("MP3VBR getDuration", duratoinWithinTolerence); 82 } 83 84 @MediumTest 85 public void testMIDIGetDuration() throws Exception { 86 int duration = CodecTest.getDuration(MediaNames.MIDI); 87 duratoinWithinTolerence = verifyDuration(duration, MediaNames.MIDI_LENGTH); 88 assertTrue("MIDI getDuration", duratoinWithinTolerence); 89 } 90 91 @MediumTest 92 public void testAMRGetDuration() throws Exception { 93 int duration = CodecTest.getDuration(MediaNames.AMR); 94 duratoinWithinTolerence = verifyDuration(duration, MediaNames.AMR_LENGTH); 95 assertTrue("AMR getDuration", duratoinWithinTolerence); 96 } 97 98 /* 99 public void testOGGGetDuration() throws Exception { 100 int duration = CodecTest.getDuration(MediaNames.OGG); 101 duratoinWithinTolerence = verifyDuration(duration, MediaNames.OGG_LENGTH); 102 assertTrue("OGG getDuration", duratoinWithinTolerence); 103 }*/ 104 105 106 //Test cases for GetCurrentPosition 107 @LargeTest 108 public void testMP3CBRGetCurrentPosition() throws Exception { 109 boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3CBR); 110 assertTrue("MP3CBR GetCurrentPosition", currentPosition); 111 } 112 113 @LargeTest 114 public void testMP3VBRGetCurrentPosition() throws Exception { 115 boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3VBR); 116 assertTrue("MP3VBR GetCurrentPosition", currentPosition); 117 } 118 119 @LargeTest 120 public void testMIDIGetCurrentPosition() throws Exception { 121 boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MIDI); 122 assertTrue("MIDI GetCurrentPosition", currentPosition); 123 } 124 125 @LargeTest 126 public void testAMRGetCurrentPosition() throws Exception { 127 boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.AMR); 128 assertTrue("AMR GetCurrentPosition", currentPosition); 129 } 130 131 /* 132 public void testOGGGetCurrentPosition() throws Exception { 133 boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.OGG); 134 assertTrue("OGG GetCurrentPosition", currentPosition); 135 */ 136 137 //Test cases for pause 138 @LargeTest 139 public void testMP3CBRPause() throws Exception { 140 boolean isPaused = CodecTest.pause(MediaNames.MP3CBR); 141 assertTrue("MP3CBR Pause", isPaused); 142 } 143 144 @LargeTest 145 public void testMP3VBRPause() throws Exception { 146 boolean isPaused = CodecTest.pause(MediaNames.MP3VBR); 147 assertTrue("MP3VBR Pause", isPaused); 148 } 149 150 @LargeTest 151 public void testMIDIPause() throws Exception { 152 boolean isPaused = CodecTest.pause(MediaNames.MIDI); 153 assertTrue("MIDI Pause", isPaused); 154 } 155 156 @LargeTest 157 public void testAMRPause() throws Exception { 158 boolean isPaused = CodecTest.pause(MediaNames.AMR); 159 assertTrue("AMR Pause", isPaused); 160 } 161 162 /* 163 public void testOGGPause() throws Exception { 164 boolean isPaused = CodecTest.pause(MediaNames.OGG); 165 assertTrue("OGG Pause", isPaused); 166 }*/ 167 168 @MediumTest 169 public void testMP3CBRPrepareStopRelease() throws Exception { 170 CodecTest.prepareStopRelease(MediaNames.MP3CBR); 171 assertTrue("MP3CBR prepareStopRelease", true); 172 } 173 174 @MediumTest 175 public void testMIDIPrepareStopRelease() throws Exception { 176 CodecTest.prepareStopRelease(MediaNames.MIDI); 177 assertTrue("MIDI prepareStopRelease", true); 178 } 179 180 //One test case for seek before start 181 @MediumTest 182 public void testMP3CBRSeekBeforeStart() throws Exception { 183 boolean seekBeforePlay = CodecTest.seektoBeforeStart(MediaNames.MP3CBR); 184 assertTrue("MP3CBR SeekBeforePlay", seekBeforePlay); 185 } 186 187 //Skip test - Bug# 1120249 188 /* 189 public void testMP3CBRpreparePauseRelease() throws Exception { 190 CodecTest.preparePauseRelease(MediaNames.MP3CBR); 191 assertTrue("MP3CBR preparePauseRelease", true); 192 } 193 194 public void testMIDIpreparePauseRelease() throws Exception { 195 CodecTest.preparePauseRelease(MediaNames.MIDI); 196 assertTrue("MIDI preparePauseRelease", true); 197 } 198 */ 199 200 201 //Test cases for setLooping 202 @LargeTest 203 public void testMP3CBRSetLooping() throws Exception { 204 boolean isLoop = CodecTest.setLooping(MediaNames.MP3CBR); 205 assertTrue("MP3CBR setLooping", isLoop); 206 } 207 208 @LargeTest 209 public void testMP3VBRSetLooping() throws Exception { 210 boolean isLoop = CodecTest.setLooping(MediaNames.MP3VBR); 211 Log.v(TAG, "setLooping"); 212 assertTrue("MP3VBR setLooping", isLoop); 213 } 214 215 @LargeTest 216 public void testMIDISetLooping() throws Exception { 217 boolean isLoop = CodecTest.setLooping(MediaNames.MIDI); 218 assertTrue("MIDI setLooping", isLoop); 219 } 220 221 @LargeTest 222 public void testAMRSetLooping() throws Exception { 223 boolean isLoop = CodecTest.setLooping(MediaNames.AMR); 224 assertTrue("AMR setLooping", isLoop); 225 } 226 227 /* 228 public void testOGGSetLooping() throws Exception { 229 boolean isLoop = CodecTest.setLooping(MediaNames.OGG); 230 assertTrue("OGG setLooping", isLoop); 231 } */ 232 233 //Test cases for seekTo 234 @LargeTest 235 public void testMP3CBRSeekTo() throws Exception { 236 boolean isLoop = CodecTest.seekTo(MediaNames.MP3CBR); 237 assertTrue("MP3CBR seekTo", isLoop); 238 } 239 240 @LargeTest 241 public void testMP3VBRSeekTo() throws Exception { 242 boolean isLoop = CodecTest.seekTo(MediaNames.MP3VBR); 243 Log.v(TAG, "seekTo"); 244 assertTrue("MP3VBR seekTo", isLoop); 245 } 246 247 @LargeTest 248 public void testMIDISeekTo() throws Exception { 249 boolean isLoop = CodecTest.seekTo(MediaNames.MIDI); 250 assertTrue("MIDI seekTo", isLoop); 251 } 252 253 @LargeTest 254 public void testAMRSeekTo() throws Exception { 255 boolean isLoop = CodecTest.seekTo(MediaNames.AMR); 256 assertTrue("AMR seekTo", isLoop); 257 } 258 259 /* 260 public void testOGGSeekTo() throws Exception { 261 boolean isLoop = CodecTest.seekTo(MediaNames.OGG); 262 assertTrue("OGG seekTo", isLoop); 263 }*/ 264 265 266 //Jump to the end of the files 267 @LargeTest 268 public void testMP3CBRSeekToEnd() throws Exception { 269 boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3CBR); 270 assertTrue("MP3CBR seekToEnd", isEnd); 271 } 272 273 @LargeTest 274 public void testMP3VBRSeekToEnd() throws Exception { 275 boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3VBR); 276 Log.v(TAG, "seekTo"); 277 assertTrue("MP3VBR seekToEnd", isEnd); 278 } 279 280 @LargeTest 281 public void testMIDISeekToEnd() throws Exception { 282 boolean isEnd = CodecTest.seekToEnd(MediaNames.MIDI); 283 assertTrue("MIDI seekToEnd", isEnd); 284 } 285 286 @LargeTest 287 public void testAMRSeekToEnd() throws Exception { 288 boolean isEnd = CodecTest.seekToEnd(MediaNames.AMR); 289 assertTrue("AMR seekToEnd", isEnd); 290 } 291 292 /* 293 public void testOGGSeekToEnd() throws Exception { 294 boolean isEnd = CodecTest.seekToEnd(MediaNames.OGG); 295 assertTrue("OGG seekToEnd", isEnd); 296 }*/ 297 298 @LargeTest 299 public void testWAVSeekToEnd() throws Exception { 300 boolean isEnd = CodecTest.seekToEnd(MediaNames.WAV); 301 assertTrue("WAV seekToEnd", isEnd); 302 } 303 304 @MediumTest 305 public void testLargeVideoHeigth() throws Exception { 306 int height = 0; 307 height = CodecTest.videoHeight(MediaNames.VIDEO_LARGE_SIZE_3GP); 308 Log.v(TAG, "Video height = " + height); 309 assertEquals("streaming video height", 240, height); 310 } 311 312 @MediumTest 313 public void testLargeVideoWidth() throws Exception { 314 int width = 0; 315 width = CodecTest.videoWidth(MediaNames.VIDEO_LARGE_SIZE_3GP); 316 Log.v(TAG, "Video width = " + width); 317 assertEquals("streaming video width", 320, width); 318 } 319 320 @LargeTest 321 public void testVideoMP4SeekTo() throws Exception { 322 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_MP4); 323 assertTrue("Local MP4 SeekTo", isSeek); 324 } 325 326 @LargeTest 327 public void testVideoH263AACSeekTo() throws Exception { 328 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AAC); 329 assertTrue("H263AAC SeekTo", isSeek); 330 } 331 332 @LargeTest 333 public void testVideoH263AMRSeekTo() throws Exception { 334 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AMR); 335 assertTrue("H263AMR SeekTo", isSeek); 336 } 337 338 @LargeTest 339 public void testVideoH264AACSeekTo() throws Exception { 340 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AAC); 341 assertTrue("H264AAC SeekTo", isSeek); 342 } 343 344 @LargeTest 345 public void testVideoH264AMRSeekTo() throws Exception { 346 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AMR); 347 assertTrue("H264AMR SeekTo", isSeek); 348 } 349 350 @LargeTest 351 public void testVideoWebmSeekTo() throws Exception { 352 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_WEBM); 353 assertTrue("WEBM SeekTo", isSeek); 354 } 355 356 @LargeTest 357 public void testSoundRecord() throws Exception { 358 boolean isRecordered = CodecTest.mediaRecorderRecord(MediaNames.RECORDER_OUTPUT); 359 assertTrue("Recorder", isRecordered); 360 } 361 362 @LargeTest 363 public void testGetThumbnail() throws Exception { 364 boolean getThumbnail = CodecTest.getThumbnail(MediaNames.VIDEO_H264_AAC, MediaNames.GOLDEN_THUMBNAIL_OUTPUT); 365 assertTrue("Get Thumbnail", getThumbnail); 366 } 367 368 //Play a mid file which the duration is around 210 seconds 369 @LargeTest 370 public void testMidiResources() throws Exception { 371 boolean midiResources = CodecTest.resourcesPlayback(MediaFrameworkTest.midiafd,16000); 372 assertTrue("Play midi from resources", midiResources); 373 } 374 375 @LargeTest 376 public void testMp3Resources() throws Exception { 377 boolean mp3Resources = CodecTest.resourcesPlayback(MediaFrameworkTest.mp3afd,25000); 378 assertTrue("Play mp3 from resources", mp3Resources); 379 } 380 381 @MediumTest 382 public void testPrepareAsyncReset() throws Exception { 383 //assertTrue(MediaFrameworkTest.checkStreamingServer()); 384 boolean isReset = CodecTest.prepareAsyncReset(MediaNames.STREAM_MP3); 385 assertTrue("PrepareAsync Reset", isReset); 386 } 387 388 @MediumTest 389 public void testIsLooping() throws Exception { 390 boolean isLooping = CodecTest.isLooping(MediaNames.AMR); 391 assertTrue("isLooping", isLooping); 392 } 393 394 @MediumTest 395 public void testIsLoopingAfterReset() throws Exception { 396 boolean isLooping = CodecTest.isLoopingAfterReset(MediaNames.AMR); 397 assertTrue("isLooping after reset", isLooping); 398 } 399 400 @LargeTest 401 public void testLocalMp3PrepareAsyncCallback() throws Exception { 402 boolean onPrepareSuccess = 403 CodecTest.prepareAsyncCallback(MediaNames.MP3CBR, false); 404 assertTrue("LocalMp3prepareAsyncCallback", onPrepareSuccess); 405 } 406 407 @LargeTest 408 public void testLocalH263AMRPrepareAsyncCallback() throws Exception { 409 boolean onPrepareSuccess = 410 CodecTest.prepareAsyncCallback(MediaNames.VIDEO_H263_AMR, false); 411 assertTrue("testLocalH263AMRPrepareAsyncCallback", onPrepareSuccess); 412 } 413 414 @LargeTest 415 public void testStreamPrepareAsyncCallback() throws Exception { 416 //assertTrue(MediaFrameworkTest.checkStreamingServer()); 417 boolean onPrepareSuccess = 418 CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, false); 419 assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess); 420 } 421 422 @LargeTest 423 public void testStreamPrepareAsyncCallbackReset() throws Exception { 424 //assertTrue(MediaFrameworkTest.checkStreamingServer()); 425 boolean onPrepareSuccess = 426 CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, true); 427 assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess); 428 } 429 } 430