• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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 android.mediastress.cts;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.media.MediaFormat;
23 import android.net.Uri;
24 import android.os.Bundle;
25 import android.os.PowerManager;
26 import android.util.Log;
27 import android.view.SurfaceHolder;
28 import android.view.SurfaceView;
29 
30 import android.mediastress.cts.R;
31 
32 public class MediaFrameworkTest extends Activity implements SurfaceHolder.Callback {
33     private static String TAG = "MediaFrameworkTest";
34     private static SurfaceView mSurfaceView;
35 
36     private PowerManager.WakeLock mWakeLock = null;
37 
getSurfaceView()38     public static SurfaceView getSurfaceView() {
39         return mSurfaceView;
40     }
41 
42     /** Called when the activity is first created. */
43     @Override
onCreate(Bundle icicle)44     public void onCreate(Bundle icicle) {
45         super.onCreate(icicle);
46         setContentView(R.layout.surface_view);
47         mSurfaceView = (SurfaceView)findViewById(R.id.surface_view);
48         mSurfaceView.getHolder().addCallback(this);
49 
50         //Acquire the full wake lock to keep the device up
51         PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
52         mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MediaFrameworkTest");
53         mWakeLock.setReferenceCounted(false);
54     }
55 
56     @Override
onResume()57     protected void onResume() {
58         Log.v(TAG, "onResume, acquire wakelock");
59         super.onResume();
60         mWakeLock.acquire();
61     }
62 
63     @Override
onPause()64     protected void onPause() {
65         Log.v(TAG, "onPause, release wakelock");
66         mWakeLock.release();
67         super.onPause();
68     }
69 
surfaceDestroyed(SurfaceHolder holder)70     public void surfaceDestroyed(SurfaceHolder holder) {
71         //Can do nothing in here. The test case will fail if the surface destroyed.
72         Log.v(TAG, "Test application surface destroyed");
73     }
74 
surfaceChanged(SurfaceHolder holder, int format, int w, int h)75     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
76         //Do nothing in here. Just print out the log
77         Log.v(TAG, "Test application surface changed");
78     }
79 
surfaceCreated(SurfaceHolder holder)80     public void surfaceCreated(SurfaceHolder holder) {
81         holder.addCallback(this);
82         Log.v(TAG, "Test application surface created");
83     }
84 
startPlayback(String filename)85     public void startPlayback(String filename){
86       String mimetype = MediaFormat.MIMETYPE_AUDIO_MPEG;
87       Uri path = Uri.parse(filename);
88       Intent intent = new Intent(Intent.ACTION_VIEW);
89       intent.setDataAndType(path, mimetype);
90       startActivity(intent);
91     }
92 }
93