1 /* 2 * Copyright (C) 2011 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; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.res.AssetFileDescriptor; 23 import android.graphics.Color; 24 import android.media.MediaPlayer; 25 import android.net.Uri; 26 import android.os.Bundle; 27 import android.os.PowerManager; 28 import android.provider.Downloads; 29 import android.util.Log; 30 import android.util.Log; 31 import android.view.KeyEvent; 32 import android.view.Menu; 33 import android.view.SurfaceHolder; 34 import android.view.SurfaceView; 35 import android.view.View.OnClickListener; 36 import android.view.View; 37 import android.view.ViewGroup; 38 import android.widget.Button; 39 import android.widget.EditText; 40 import android.widget.MediaController; 41 import android.widget.VideoView; 42 import com.android.mediaframeworktest.MediaNames; 43 44 import android.graphics.Bitmap; 45 import android.widget.ImageView; 46 47 import java.io.File; 48 import java.io.FileDescriptor; 49 import java.net.InetAddress; 50 51 52 public class MediaFrameworkTest extends Activity implements SurfaceHolder.Callback { 53 54 //public static Surface video_sf; 55 public static SurfaceView mSurfaceView; 56 private MediaController mMediaController; 57 private String urlpath; 58 private MediaPlayer mpmidi; 59 private MediaPlayer mpmp3; 60 private String testfilepath = "/sdcard/awb.awb"; 61 62 public static AssetFileDescriptor midiafd; 63 public static AssetFileDescriptor mp3afd; 64 65 public static Bitmap mDestBitmap; 66 public static ImageView mOverlayView; 67 private SurfaceHolder mSurfaceHolder = null; 68 private String TAG = "MediaFrameworkTest"; 69 private PowerManager.WakeLock mWakeLock = null; 70 71 public MediaFrameworkTest() { 72 } 73 74 /** Called when the activity is first created. */ 75 @Override 76 public void onCreate(Bundle icicle) { 77 super.onCreate(icicle); 78 setContentView(R.layout.surface_view); 79 mSurfaceView = (SurfaceView)findViewById(R.id.surface_view); 80 mOverlayView = (ImageView)findViewById(R.id.overlay_layer); 81 ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams(); 82 mSurfaceHolder = mSurfaceView.getHolder(); 83 mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 84 mSurfaceHolder.addCallback(this); 85 86 //Get the midi fd 87 midiafd = this.getResources().openRawResourceFd(R.raw.testmidi); 88 89 //Get the mp3 fd 90 mp3afd = this.getResources().openRawResourceFd(R.raw.testmp3); 91 mOverlayView.setLayoutParams(lp); 92 mDestBitmap = Bitmap.createBitmap((int)640, (int)480, Bitmap.Config.ARGB_8888); 93 mOverlayView.setImageBitmap(mDestBitmap); 94 95 //Acquire the full wake lock to keep the device up 96 PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); 97 mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MediaFrameworkTest"); 98 mWakeLock.acquire(); 99 } 100 101 public void onStop(Bundle icicle) { 102 mWakeLock.release(); 103 } 104 105 public void surfaceDestroyed(SurfaceHolder holder) { 106 //Can do nothing in here. The test case will fail if the surface destroyed. 107 Log.v(TAG, "Test application surface destroyed"); 108 mSurfaceHolder = null; 109 } 110 111 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 112 //Do nothing in here. Just print out the log 113 Log.v(TAG, "Test application surface changed"); 114 } 115 116 public void surfaceCreated(SurfaceHolder holder) { 117 } 118 119 public void startPlayback(String filename){ 120 String mimetype = "audio/mpeg"; 121 Uri path = Uri.parse(filename); 122 Intent intent = new Intent(Intent.ACTION_VIEW); 123 intent.setDataAndType(path, mimetype); 124 startActivity(intent); 125 } 126 127 public static boolean checkStreamingServer() throws Exception { 128 InetAddress address = InetAddress.getByAddress(MediaNames.STREAM_SERVER); 129 return address.isReachable(10000); 130 } 131 132 public static void testInvalidateOverlay() { 133 mOverlayView.invalidate(); 134 } 135 136 } 137