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