只有在拍摄录像时才能显示黑色屏幕的roid模拟器。 我的法典如下。
我在标识表中发现的错误是:
10-30 06:49:35.663: W/GraphicBufferAllocator(33): alloc(160, 128, 842094169, 00002930, ...) failed -22 (Invalid argument)
10-30 06:49:35.663: E/SurfaceFlinger(33): GraphicBufferAlloc::createGraphicBuffer(w=160, h=128) failed (Invalid argument), handle=0x0
10-30 06:49:35.663: E/SurfaceTexture(33): [SurfaceView] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
10-30 06:49:35.673: W/SoftwareRenderer(35): Surface::dequeueBuffer returned error -22
录像高度和宽度
10-30 06:49:35.223: D/Video Height:(595): 128
10-30 06:49:35.223: D/Video Width:(595): 160
我想的是,甲状腺可能 t着这种大小的录像,但似乎很.。 我曾尝试过几部录像,并且可以拍摄其中的任何录像(第4条或第3条)。 我只听到了声音。 录像是黑色的。 我可以在VLC中玩.,因此录像文件被罚款。 就在 and模拟器中,我可以发挥这种作用。
I m 用Ath4.0作为我的AVD。 Ie the simulator on PC.
package com.jevan.mediaplayer;
import java.io.IOException;
import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MediaPlayerActivity extends Activity
implements SurfaceHolder.Callback, OnPreparedListener,
OnVideoSizeChangedListener {
/** Called when the activity is first created. */
private int mVideoWidth=0;
private int mVideoHeight=0;
private MediaPlayer mp = null;
private SurfaceHolder holder = null;
private SurfaceView sv = null;
private boolean mIsVideoReadyToBePlayed = false;
private boolean mIsVideoSizeKnown = false;
private Button myButton = null;
public void surfaceCreated(SurfaceHolder holder) {
/*MediaPlayer mediaPlayer = MediaPlayer.create(context, uri);
mediaPlayer.start(); // no need to call prepare(); create() does that for you
*/
Log.d("surfaceCreated()", "surfaceCreated called");
mp = new MediaPlayer();
AssetFileDescriptor afd = null;
try {
afd = getAssets().openFd("747.3gp");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
afd.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
/*
try {
mp.setDataSource("http://www.mp4point.com/downloads/d7c320246079.mp4");
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
*/
mp.setDisplay(holder);
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.setOnPreparedListener(this);
mp.setOnVideoSizeChangedListener(this);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
/*setVolumeControlStream(AudioManager.STREAM_MUSIC);*/
mp.setScreenOnWhilePlaying(true);
Log.d("Video Height:", Integer.toString(mp.getVideoHeight()));
Log.d("Video Width:", Integer.toString(mp.getVideoWidth()));
mp.setLooping(false);
//mp.start();
// i.e. react on the end of the music-file:
/*
mp.setOnCompletionListener(new
OnCompletionListener(){
public void onCompletion(MediaPlayer arg0) {
// File has ended
}
});
*/
Log.d("surfaceCreated()", "surfaceCreated finishing");
}
public void surfaceChanged(SurfaceHolder holder,
int format, int width, int height) {
// TODO Auto-generated method stub
}
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
public void onPrepared(MediaPlayer mediaplayer) {
Log.d("onPrepared", "onPrepared called");
mIsVideoReadyToBePlayed = true;
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback(mediaplayer);
}
Log.d("onPrepared", "onPrepared finishing");
}
private void startVideoPlayback(MediaPlayer mediaplayer) {
if (!(mediaplayer.isPlaying())) {
holder.setFixedSize(mVideoWidth, mVideoHeight);
mediaplayer.start();
}
}
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
Log.d("onVideoSizeChanged",
"onVideoSizeChanged called (Width "+Integer.toString(width)+" Height "+Integer.toString(height)+")");
if (width == 0 || height == 0) {
Log.e("Log", "invalid video width(" + width + ") or height(" + height + ")");
return;
}
mIsVideoSizeKnown = true;
mVideoWidth = width;
mVideoHeight = height;
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback(mp);
}
}
private void releaseMediaPlayer() {
Log.d("releaseMediaPlayer", "releaseMediaPlayer called");
if (mp != null) {
mp.release();
mp = null;
Log.d("releaseMediaPlayer", "mp release has been called and mp made null");
}
}
@Override
protected void onPause() {
super.onPause();
releaseMediaPlayer();
doCleanUp();
}
@Override
protected void onDestroy() {
super.onDestroy();
releaseMediaPlayer();
doCleanUp();
}
private void doCleanUp() {
mVideoWidth = 0;
mVideoHeight = 0;
mIsVideoReadyToBePlayed = false;
mIsVideoSizeKnown = false;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("onCreate", "onCreate called");
sv = (SurfaceView) findViewById(R.id.surface_view);
holder = sv.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
myButton = (Button)this.findViewById(R.id.button);
myButton.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback(mp);
}
}
});
Log.d("onCreate", "onCreate finishing");
}
}
My main.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/button"
android:text="Start Video" android:layout_alignParentBottom="true" />
<SurfaceView android:id="@+id/surface_view"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_above="@+id/button"></SurfaceView>
</RelativeLayout>