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 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.provider.Downloads; 28 import android.util.Log; 29 import android.util.Log; 30 import android.view.KeyEvent; 31 import android.view.Menu; 32 import android.view.SurfaceHolder; 33 import android.view.SurfaceView; 34 import android.view.View.OnClickListener; 35 import android.view.View; 36 import android.view.ViewGroup; 37 import android.widget.Button; 38 import android.widget.EditText; 39 import android.widget.MediaController; 40 import android.widget.VideoView; 41 import com.android.mediaframeworktest.MediaNames; 42 43 import java.io.File; 44 import java.io.FileDescriptor; 45 import java.net.InetAddress; 46 47 48 public class MediaFrameworkTest extends Activity { 49 50 //public static Surface video_sf; 51 public static SurfaceView mSurfaceView; 52 private MediaController mMediaController; 53 private String urlpath; 54 private MediaPlayer mpmidi; 55 private MediaPlayer mpmp3; 56 private String testfilepath = "/sdcard/awb.awb"; 57 58 public static AssetFileDescriptor midiafd; 59 public static AssetFileDescriptor mp3afd; 60 61 62 public MediaFrameworkTest() { 63 } 64 65 66 /** Called when the activity is first created. */ 67 @Override 68 public void onCreate(Bundle icicle) { 69 super.onCreate(icicle); 70 setContentView(R.layout.surface_view); 71 mSurfaceView = (SurfaceView)findViewById(R.id.surface_view); 72 ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams(); 73 mSurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 74 75 //Get the midi fd 76 midiafd = this.getResources().openRawResourceFd(R.raw.testmidi); 77 78 //Get the mp3 fd 79 mp3afd = this.getResources().openRawResourceFd(R.raw.testmp3); 80 } 81 82 public void startPlayback(String filename){ 83 String mimetype = "audio/mpeg"; 84 Uri path = Uri.parse(filename); 85 Intent intent = new Intent(Intent.ACTION_VIEW); 86 intent.setDataAndType(path, mimetype); 87 startActivity(intent); 88 } 89 90 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { 91 switch (keyCode) { 92 case KeyEvent.KEYCODE_0: 93 MediaPlayer mp = new MediaPlayer(); 94 try{ 95 mp.setDataSource(MediaNames.VIDEO_RTSP3GP); 96 Log.v("emily","awb " + testfilepath); 97 mp.setDisplay(mSurfaceView.getHolder()); 98 mp.prepare(); 99 mp.start(); 100 }catch (Exception e){} 101 break; 102 103 //start the music player intent with the test URL from PV 104 case KeyEvent.KEYCODE_1: 105 startPlayback(MediaNames.STREAM_MP3_1); 106 break; 107 108 case KeyEvent.KEYCODE_2: 109 startPlayback(MediaNames.STREAM_MP3_2); 110 break; 111 112 case KeyEvent.KEYCODE_3: 113 startPlayback(MediaNames.STREAM_MP3_3); 114 break; 115 116 case KeyEvent.KEYCODE_4: 117 startPlayback(MediaNames.STREAM_MP3_4); 118 break; 119 120 case KeyEvent.KEYCODE_5: 121 startPlayback(MediaNames.STREAM_MP3_5); 122 break; 123 124 case KeyEvent.KEYCODE_6: 125 startPlayback(MediaNames.STREAM_MP3_6); 126 break; 127 128 case KeyEvent.KEYCODE_7: 129 startPlayback(MediaNames.STREAM_MP3_7); 130 break; 131 132 case KeyEvent.KEYCODE_8: 133 startPlayback(MediaNames.STREAM_MP3_8); 134 break; 135 136 case KeyEvent.KEYCODE_9: 137 startPlayback(MediaNames.STREAM_MP3_9); 138 break; 139 140 141 142 } 143 return super.onKeyDown(keyCode, event); 144 145 } 146 147 public static boolean checkStreamingServer() throws Exception { 148 InetAddress address = InetAddress.getByAddress(MediaNames.STREAM_SERVER); 149 return address.isReachable(10000); 150 } 151 } 152