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