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
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.os.PowerManager;
28import android.provider.Downloads;
29import android.util.Log;
30import android.util.Log;
31import android.view.KeyEvent;
32import android.view.Menu;
33import android.view.SurfaceHolder;
34import android.view.SurfaceView;
35import android.view.View.OnClickListener;
36import android.view.View;
37import android.view.ViewGroup;
38import android.widget.Button;
39import android.widget.EditText;
40import android.widget.MediaController;
41import android.widget.VideoView;
42import com.android.mediaframeworktest.MediaNames;
43
44import android.graphics.Bitmap;
45import android.widget.ImageView;
46
47import java.io.File;
48import java.io.FileDescriptor;
49import java.net.InetAddress;
50
51
52public 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    @Override
102    public void onDestroy() {
103        super.onDestroy();
104        mWakeLock.release();
105    }
106
107    public void surfaceDestroyed(SurfaceHolder holder) {
108        //Can do nothing in here. The test case will fail if the surface destroyed.
109        Log.v(TAG, "Test application surface destroyed");
110        mSurfaceHolder = null;
111    }
112
113    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
114        //Do nothing in here. Just print out the log
115        Log.v(TAG, "Test application surface changed");
116    }
117
118    public void surfaceCreated(SurfaceHolder holder) {
119    }
120
121    public void startPlayback(String filename){
122      String mimetype = "audio/mpeg";
123      Uri path = Uri.parse(filename);
124      Intent intent = new Intent(Intent.ACTION_VIEW);
125      intent.setDataAndType(path, mimetype);
126      startActivity(intent);
127    }
128
129  public static boolean checkStreamingServer() throws Exception {
130      InetAddress address = InetAddress.getByAddress(MediaNames.STREAM_SERVER);
131      return address.isReachable(10000);
132  }
133
134  public static void testInvalidateOverlay() {
135      mOverlayView.invalidate();
136  }
137
138}
139