2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.mediaframeworktest.functional;
19 import com.android.mediaframeworktest.MediaFrameworkTest;
20 import com.android.mediaframeworktest.MediaNames;
21 import com.android.mediaframeworktest.MediaProfileReader;
23 import android.content.Context;
24 import android.test.ActivityInstrumentationTestCase;
25 import android.util.Log;
26 import android.test.suitebuilder.annotation.LargeTest;
27 import android.test.suitebuilder.annotation.MediumTest;
28 import android.test.suitebuilder.annotation.Suppress;
33 * Junit / Instrumentation test case for the media player api
36 public 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;
44 public MediaPlayerApiTest() {
45 super("com.android.mediaframeworktest", MediaFrameworkTest.class);
46 isWMAEnable = MediaProfileReader.getWMAEnable();
47 isWMVEnable = MediaProfileReader.getWMVEnable();
50 protected void setUp() throws Exception {
55 public boolean verifyDuration(int duration, int expectedDuration){
56 if ((duration > expectedDuration * 1.1) || (duration < expectedDuration * 0.9))
65 //Wait for PV bugs for MP3 duration
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);
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);
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);
89 public void testWMA9GetDuration() throws Exception {
91 int duration = CodecTest.getDuration(MediaNames.WMA9);
92 duratoinWithinTolerence = verifyDuration(duration, MediaNames.WMA9_LENGTH);
93 assertTrue("WMA9 getDuration", duratoinWithinTolerence);
98 public void testAMRGetDuration() throws Exception {
99 int duration = CodecTest.getDuration(MediaNames.AMR);
100 duratoinWithinTolerence = verifyDuration(duration, MediaNames.AMR_LENGTH);
101 assertTrue("AMR getDuration", duratoinWithinTolerence);
105 public void testOGGGetDuration() throws Exception {
106 int duration = CodecTest.getDuration(MediaNames.OGG);
107 duratoinWithinTolerence = verifyDuration(duration, MediaNames.OGG_LENGTH);
108 assertTrue("OGG getDuration", duratoinWithinTolerence);
112 //Test cases for GetCurrentPosition
114 public void testMP3CBRGetCurrentPosition() throws Exception {
115 boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3CBR);
116 assertTrue("MP3CBR GetCurrentPosition", currentPosition);
120 public void testMP3VBRGetCurrentPosition() throws Exception {
121 boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3VBR);
122 assertTrue("MP3VBR GetCurrentPosition", currentPosition);
126 public void testMIDIGetCurrentPosition() throws Exception {
127 boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MIDI);
128 assertTrue("MIDI GetCurrentPosition", currentPosition);
132 public void testWMA9GetCurrentPosition() throws Exception {
134 boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.WMA9);
135 assertTrue("WMA9 GetCurrentPosition", currentPosition);
140 public void testAMRGetCurrentPosition() throws Exception {
141 boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.AMR);
142 assertTrue("AMR GetCurrentPosition", currentPosition);
146 public void testOGGGetCurrentPosition() throws Exception {
147 boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.OGG);
148 assertTrue("OGG GetCurrentPosition", currentPosition);
151 //Test cases for pause
153 public void testMP3CBRPause() throws Exception {
154 boolean isPaused = CodecTest.pause(MediaNames.MP3CBR);
155 assertTrue("MP3CBR Pause", isPaused);
159 public void testMP3VBRPause() throws Exception {
160 boolean isPaused = CodecTest.pause(MediaNames.MP3VBR);
161 assertTrue("MP3VBR Pause", isPaused);
165 public void testMIDIPause() throws Exception {
166 boolean isPaused = CodecTest.pause(MediaNames.MIDI);
167 assertTrue("MIDI Pause", isPaused);
171 public void testWMA9Pause() throws Exception {
173 boolean isPaused = CodecTest.pause(MediaNames.WMA9);
174 assertTrue("WMA9 Pause", isPaused);
179 public void testAMRPause() throws Exception {
180 boolean isPaused = CodecTest.pause(MediaNames.AMR);
181 assertTrue("AMR Pause", isPaused);
185 public void testOGGPause() throws Exception {
186 boolean isPaused = CodecTest.pause(MediaNames.OGG);
187 assertTrue("OGG Pause", isPaused);
191 public void testMP3CBRPrepareStopRelease() throws Exception {
192 CodecTest.prepareStopRelease(MediaNames.MP3CBR);
193 assertTrue("MP3CBR prepareStopRelease", true);
197 public void testMIDIPrepareStopRelease() throws Exception {
198 CodecTest.prepareStopRelease(MediaNames.MIDI);
199 assertTrue("MIDI prepareStopRelease", true);
202 //One test case for seek before start
204 public void testMP3CBRSeekBeforeStart() throws Exception {
205 boolean seekBeforePlay = CodecTest.seektoBeforeStart(MediaNames.MP3CBR);
206 assertTrue("MP3CBR SeekBeforePlay", seekBeforePlay);
209 //Skip test - Bug# 1120249
211 public void testMP3CBRpreparePauseRelease() throws Exception {
212 CodecTest.preparePauseRelease(MediaNames.MP3CBR);
213 assertTrue("MP3CBR preparePauseRelease", true);
216 public void testMIDIpreparePauseRelease() throws Exception {
217 CodecTest.preparePauseRelease(MediaNames.MIDI);
218 assertTrue("MIDI preparePauseRelease", true);
223 //Test cases for setLooping
225 public void testMP3CBRSetLooping() throws Exception {
226 boolean isLoop = CodecTest.setLooping(MediaNames.MP3CBR);
227 assertTrue("MP3CBR setLooping", isLoop);
231 public void testMP3VBRSetLooping() throws Exception {
232 boolean isLoop = CodecTest.setLooping(MediaNames.MP3VBR);
233 Log.v(TAG, "setLooping");
234 assertTrue("MP3VBR setLooping", isLoop);
238 public void testMIDISetLooping() throws Exception {
239 boolean isLoop = CodecTest.setLooping(MediaNames.MIDI);
240 assertTrue("MIDI setLooping", isLoop);
244 public void testWMA9SetLooping() throws Exception {
246 boolean isLoop = CodecTest.setLooping(MediaNames.WMA9);
247 assertTrue("WMA9 setLooping", isLoop);
252 public void testAMRSetLooping() throws Exception {
253 boolean isLoop = CodecTest.setLooping(MediaNames.AMR);
254 assertTrue("AMR setLooping", isLoop);
258 public void testOGGSetLooping() throws Exception {
259 boolean isLoop = CodecTest.setLooping(MediaNames.OGG);
260 assertTrue("OGG setLooping", isLoop);
263 //Test cases for seekTo
265 public void testMP3CBRSeekTo() throws Exception {
266 boolean isLoop = CodecTest.seekTo(MediaNames.MP3CBR);
267 assertTrue("MP3CBR seekTo", isLoop);
271 public void testMP3VBRSeekTo() throws Exception {
272 boolean isLoop = CodecTest.seekTo(MediaNames.MP3VBR);
273 Log.v(TAG, "seekTo");
274 assertTrue("MP3VBR seekTo", isLoop);
278 public void testMIDISeekTo() throws Exception {
279 boolean isLoop = CodecTest.seekTo(MediaNames.MIDI);
280 assertTrue("MIDI seekTo", isLoop);
284 public void testWMA9SeekTo() throws Exception {
286 boolean isLoop = CodecTest.seekTo(MediaNames.WMA9);
287 assertTrue("WMA9 seekTo", isLoop);
292 public void testAMRSeekTo() throws Exception {
293 boolean isLoop = CodecTest.seekTo(MediaNames.AMR);
294 assertTrue("AMR seekTo", isLoop);
298 public void testOGGSeekTo() throws Exception {
299 boolean isLoop = CodecTest.seekTo(MediaNames.OGG);
300 assertTrue("OGG seekTo", isLoop);
304 //Jump to the end of the files
306 public void testMP3CBRSeekToEnd() throws Exception {
307 boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3CBR);
308 assertTrue("MP3CBR seekToEnd", isEnd);
312 public void testMP3VBRSeekToEnd() throws Exception {
313 boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3VBR);
314 Log.v(TAG, "seekTo");
315 assertTrue("MP3VBR seekToEnd", isEnd);
319 public void testMIDISeekToEnd() throws Exception {
320 boolean isEnd = CodecTest.seekToEnd(MediaNames.MIDI);
321 assertTrue("MIDI seekToEnd", isEnd);
326 public void testWMA9SeekToEnd() throws Exception {
328 boolean isEnd = CodecTest.seekToEnd(MediaNames.WMA9);
329 assertTrue("WMA9 seekToEnd", isEnd);
334 public void testAMRSeekToEnd() throws Exception {
335 boolean isEnd = CodecTest.seekToEnd(MediaNames.AMR);
336 assertTrue("AMR seekToEnd", isEnd);
340 public void testOGGSeekToEnd() throws Exception {
341 boolean isEnd = CodecTest.seekToEnd(MediaNames.OGG);
342 assertTrue("OGG seekToEnd", isEnd);
346 public void testWAVSeekToEnd() throws Exception {
348 boolean isEnd = CodecTest.seekToEnd(MediaNames.WAV);
349 assertTrue("WAV seekToEnd", isEnd);
354 public void testLargeVideoHeigth() throws Exception {
356 height = CodecTest.videoHeight(MediaNames.VIDEO_LARGE_SIZE_3GP);
357 Log.v(TAG, "Video height = " + height);
358 assertEquals("streaming video height", 240, height);
362 public void testLargeVideoWidth() throws Exception {
364 width = CodecTest.videoWidth(MediaNames.VIDEO_LARGE_SIZE_3GP);
365 Log.v(TAG, "Video width = " + width);
366 assertEquals("streaming video width", 320, width);
370 public void testVideoMP4SeekTo() throws Exception {
371 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_MP4);
372 assertTrue("Local MP4 SeekTo", isSeek);
376 public void testVideoLong3gpSeekTo() throws Exception {
377 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_LONG_3GP);
378 assertTrue("Local 3gp SeekTo", isSeek);
382 public void testVideoH263AACSeekTo() throws Exception {
383 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AAC);
384 assertTrue("H263AAC SeekTo", isSeek);
388 public void testVideoH263AMRSeekTo() throws Exception {
389 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AMR);
390 assertTrue("H263AMR SeekTo", isSeek);
394 public void testVideoH264AACSeekTo() throws Exception {
395 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AAC);
396 assertTrue("H264AAC SeekTo", isSeek);
400 public void testVideoH264AMRSeekTo() throws Exception {
401 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AMR);
402 assertTrue("H264AMR SeekTo", isSeek);
406 public void testVideoWMVSeekTo() throws Exception {
407 Log.v(TAG, "wmv not enable");
409 Log.v(TAG, "wmv enable");
410 boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_WMV);
411 assertTrue("WMV SeekTo", isSeek);
416 public void testSoundRecord() throws Exception {
417 boolean isRecordered = CodecTest.mediaRecorderRecord(MediaNames.RECORDER_OUTPUT);
418 assertTrue("Recorder", isRecordered);
422 public void testGetThumbnail() throws Exception {
423 boolean getThumbnail = CodecTest.getThumbnail(MediaNames.VIDEO_H264_AAC, MediaNames.GOLDEN_THUMBNAIL_OUTPUT_2);
424 assertTrue("Get Thumbnail", getThumbnail);
427 //Play a mid file which the duration is around 210 seconds
429 public void testMidiResources() throws Exception {
430 boolean midiResources = CodecTest.resourcesPlayback(MediaFrameworkTest.midiafd,16000);
431 assertTrue("Play midi from resources", midiResources);
435 public void testMp3Resources() throws Exception {
436 boolean mp3Resources = CodecTest.resourcesPlayback(MediaFrameworkTest.mp3afd,25000);
437 assertTrue("Play mp3 from resources", mp3Resources);
441 public void testPrepareAsyncReset() throws Exception {
442 //assertTrue(MediaFrameworkTest.checkStreamingServer());
443 boolean isReset = CodecTest.prepareAsyncReset(MediaNames.STREAM_MP3);
444 assertTrue("PrepareAsync Reset", isReset);
448 public void testIsLooping() throws Exception {
449 boolean isLooping = CodecTest.isLooping(MediaNames.AMR);
450 assertTrue("isLooping", isLooping);
454 public void testIsLoopingAfterReset() throws Exception {
455 boolean isLooping = CodecTest.isLoopingAfterReset(MediaNames.AMR);
456 assertTrue("isLooping after reset", isLooping);
460 public void testLocalMp3PrepareAsyncCallback() throws Exception {
461 boolean onPrepareSuccess =
462 CodecTest.prepareAsyncCallback(MediaNames.MP3CBR, false);
463 assertTrue("LocalMp3prepareAsyncCallback", onPrepareSuccess);
467 public void testLocalH263AMRPrepareAsyncCallback() throws Exception {
468 boolean onPrepareSuccess =
469 CodecTest.prepareAsyncCallback(MediaNames.VIDEO_H263_AMR, false);
470 assertTrue("testLocalH263AMRPrepareAsyncCallback", onPrepareSuccess);
474 public void testStreamPrepareAsyncCallback() throws Exception {
475 //assertTrue(MediaFrameworkTest.checkStreamingServer());
476 boolean onPrepareSuccess =
477 CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, false);
478 assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess);
482 public void testStreamPrepareAsyncCallbackReset() throws Exception {
483 //assertTrue(MediaFrameworkTest.checkStreamingServer());
484 boolean onPrepareSuccess =
485 CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, true);
486 assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess);
489 //Provide a tool to play all kinds of media files in a directory
492 public void testMediaSamples() throws Exception {
493 // load directory files
494 boolean onCompleteSuccess = false;
495 File dir = new File(MediaNames.MEDIA_SAMPLE_POOL);
496 String[] children = dir.list();
497 if (children == null) {
498 Log.v("MediaPlayerApiTest:testMediaSamples", "dir is empty");
501 for (int i = 0; i < children.length; i++) {
502 //Get filename of directory
503 String filename = children[i];
504 Log.v("MediaPlayerApiTest",
505 "testMediaSamples: file to be played: "
506 + dir + "/" + filename);
508 CodecTest.playMediaSamples(dir + "/" + filename);
509 assertTrue("testMediaSamples", onCompleteSuccess);