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