thanks. On Nov 11, 2:55 pm, rktb <[email protected]> wrote: > You need to use the > "onVideoSizeChangedListener".http://developer.android.com/reference/android/media/MediaPlayer.OnVi... > > Please refer the example > at:http://developer.android.com/guide/samples/ApiDemos/src/com/example/a... > > -Ravi > > On Nov 11, 4:13 am, lei <[email protected]> wrote: > > > > > I figure it out, sometimes the width and height values from > > player.getVideoWidth() and player.getVideoHeight() are zero, I do not > > know why? ; > > > On Nov 10, 6:19 pm, lei <[email protected]> wrote: > > > > I am using the Android SDK 1.6. > > > > On Nov 10, 6:18 pm, lei <[email protected]> wrote: > > > > > I wrote a media player for playing video, but it encounter an error of > > > > PV SW DECODER IS USED FOR MPEG4 when I try to play back a 3gp format > > > > video, anyone knows what is it? How to solve this problem? I paste my > > > > code below: > > > > > package com.test; > > > > > import android.app.Activity; > > > > import android.content.Intent; > > > > import android.content.res.AssetFileDescriptor; > > > > import android.media.AudioManager; > > > > import android.media.MediaPlayer; > > > > import android.os.Bundle; > > > > import android.util.Log; > > > > import android.view.SurfaceHolder; > > > > import android.view.SurfaceView; > > > > > public class MediaVideoTest extends Activity implements > > > > MediaPlayer.OnPreparedListener,MediaPlayer.OnCompletionListener,SurfaceHold > > > > er.Callback > > > > { > > > > > private static final String TAG = "MediaVideoTest"; > > > > private MediaPlayer player; > > > > private SurfaceHolder holder; > > > > private SurfaceView surfaceView; > > > > private int mWidth,mHeight; > > > > > @Override > > > > protected void onCreate(Bundle savedInstanceState) { > > > > > super.onCreate(savedInstanceState); > > > > setContentView(R.layout.video_view); > > > > surfaceView = (SurfaceView) > > > > findViewById(R.id.surfaceView); > > > > holder = surfaceView.getHolder(); > > > > holder.addCallback(this); > > > > holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); > > > > > } > > > > > private void playVideo() { > > > > > try { > > > > AssetFileDescriptor asd = > > > > getResources().openRawResourceFd > > > > (R.raw.chainsaw); > > > > > //create media player > > > > player = new MediaPlayer(); > > > > > > > > player.setDataSource(asd.getFileDescriptor(),asd.getStartOffset > > > > (),asd.getLength()); > > > > player.setDisplay(holder); > > > > player.prepare(); > > > > player.setOnPreparedListener(this); > > > > player.setOnCompletionListener(this); > > > > player.setAudioStreamType(AudioManager.STREAM_MUSIC); > > > > > } catch (Exception e) { > > > > Log.e(TAG, "error: " + e.getMessage(), e); > > > > } > > > > } > > > > > @Override > > > > public void onPrepared(MediaPlayer mp) { > > > > Log.d(TAG, "onPrepared called"); > > > > mWidth = player.getVideoWidth(); > > > > mHeight = player.getVideoHeight(); > > > > Log.d(TAG, "width : " + mWidth + " height : " + > > > > mHeight); > > > > > if(mWidth != 0 && mHeight != 0){ > > > > holder.setFixedSize(mWidth, mHeight); > > > > player.start(); > > > > } > > > > } > > > > > @Override > > > > public void surfaceChanged(SurfaceHolder holder, int format, int > > > > width,int height) { > > > > Log.d(TAG, "surfaceChanged width : " + width + " height : " + > > > > height); > > > > } > > > > > @Override > > > > public void surfaceCreated(SurfaceHolder holder) { > > > > Log.d(TAG, "surfaceCreated() is called"); > > > > playVideo(); > > > > } > > > > > @Override > > > > public void surfaceDestroyed(SurfaceHolder holder) { > > > > Log.d(TAG, "surfaceDestroy() is called"); > > > > } > > > > > @Override > > > > protected void onDestroy() { > > > > super.onDestroy(); > > > > if(player != null){ > > > > player.release(); > > > > player = null; > > > > } > > > > } > > > > > @Override > > > > public void onCompletion(MediaPlayer mp) { > > > > > if(player != null){ > > > > player.release(); > > > > player = null; > > > > } > > > > > //close this activity; > > > > finish(); > > > > > //go back to the main menu > > > > Intent intent = new Intent(this,MediaTest.class); > > > > startActivity(intent); > > > > > } > > > > > }
-- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en

