Hi Susanner,

I am also facing the same problem, have you solved it?
if so, please show the code or some snippet.

waiting for your reply...

Thanks,
Manoj

On Mar 5, 9:11 am, susanner <zsusan...@163.com> wrote:
> I have met nearly the same problem, I am implementing the Mediaplayer to my 
> hardware board. I haven't tried videoview, I just implemented the video 
> player from API demo.But It can't show video. I guess there is some trick 
> with this "holder" surface, it is strange that when I delete this sentence, 
> my emulator will not show video just as the real board,
> holder.addCallback(this);
>  but I added the sentence, although my emulator can successfully play video, 
> my real hardware still like before.
> and I am a little bit curious you didn't use this "holder.addCallback(this);"
> here is my program, I haven't solved my problem yet:
>
> public class MediaPlayerDemo_Video extends Activity implements
>         OnBufferingUpdateListener, OnCompletionListener,
>         MediaPlayer.OnPreparedListener, SurfaceHolder.Callback {
>
>     private static final String TAG = "MediaPlayerDemo";
>     private int mVideoWidth;
>     private int mVideoHeight;
>     private MediaPlayer mMediaPlayer;
>     private SurfaceView mPreview;
>     private SurfaceHolder holder;
>     private String path;
>     private Bundle extras;
>     private static final String MEDIA = "media";
>     private static final int LOCAL_AUDIO = 1;
>     private static final int STREAM_AUDIO = 2;
>     private static final int RESOURCES_AUDIO = 3;
>     private static final int LOCAL_VIDEO = 4;
>     private static final int STREAM_VIDEO = 5;
>
>     /**
>      *
>      * Called when the activity is first created.
>      */
>     public void onCreate(Bundle icicle) {
>         super.onCreate(icicle);
>         setContentView(R.layout.mediaplayer_2);
>         mPreview = (SurfaceView) findViewById(R.id.surface);
>         holder = mPreview.getHolder();
>         holder.addCallback(this);
>         holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
>         extras = getIntent().getExtras();
>
>     }
>
>     private void playVideo(Integer Media) {
>         try {
>
>             switch (Media) {
>                 case LOCAL_VIDEO:
>                     /*
>                      * TODO: Set the path variable to a local media file path.
>                      */
>                     path = "";
>                   /*  if (path == "") {
>                         // Tell the user to provide a media file URL.
>                         Toast
>                                 .makeText(
>                                         MediaPlayerDemo_Video.this,
>                                         "Please edit MediaPlayerDemo_Video 
> Activity, "
>                                                 + "and set the path variable 
> to your media file path."
>                                                 + " Your media file must be 
> stored on sdcard.",
>                                         Toast.LENGTH_LONG).show();
>
>                     }*/
>                     break;
>                 case STREAM_VIDEO:
>                     /*
>                      * TODO: Set path variable to progressive streamable mp4 
> or
>                      * 3gpp format URL. Http protocol should be used.
>                      * Mediaplayer can only play "progressive streamable
>                      * contents" which basically means: 1. the movie atom has 
> to
>                      * precede all the media data atoms. 2. The clip has to be
>                      * reasonably interleaved.
>                      *
>                      */
>                     path = "";
>                     if (path == "") {
>                         // Tell the user to provide a media file URL.
>                         Toast
>                                 .makeText(
>                                         MediaPlayerDemo_Video.this,
>                                         "Please edit MediaPlayerDemo_Video 
> Activity,"
>                                                 + " and set the path variable 
> to your media file URL.",
>                                         Toast.LENGTH_LONG).show();
>
>                     }
>
>                     break;
>
>             }
>
>             // Create a new media player and set the listeners
>             mMediaPlayer = new MediaPlayer();
>             AssetFileDescriptor afd = getResources().openRawResourceFd
>             (R.raw.movie);
>             Log.v(TAG,afd.toString());
>             mMediaPlayer.setDataSource(afd.getFileDescriptor(),
>             afd.getStartOffset(), afd.getLength());
>
>           // mMediaPlayer.setDataSource(path);
>             mMediaPlayer.setDisplay(holder);
>             mMediaPlayer.prepare();
>             mMediaPlayer.setOnBufferingUpdateListener(this);
>             mMediaPlayer.setOnCompletionListener(this);
>             mMediaPlayer.setOnPreparedListener(this);                        
> mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
>             Log.d(TAG, "mMediaPlayer.start is to be called");
>             mMediaPlayer.start();
>
>         } catch (Exception e) {
>             Log.e(TAG, "error: " + e.getMessage(), e);
>         }
>     }
>
>     public void onBufferingUpdate(MediaPlayer arg0, int percent) {
>         Log.d(TAG, "onBufferingUpdate percent:" + percent);
>
>     }
>     /**
>      * you don't call onPrepared() yourself. If you set an
>      *PreparedListener, its onPrepared() method will be called for you.
>      */
>     public void onCompletion(MediaPlayer arg0) {
>         Log.d(TAG, "onCompletion called");
>     }
>
>     public void onPrepared(MediaPlayer mediaplayer) {
>         Log.d(TAG, "onPrepared called");
>         mVideoWidth = mMediaPlayer.getVideoWidth();
>         mVideoHeight = mMediaPlayer.getVideoHeight();
>         if (mVideoWidth != 0 && mVideoHeight != 0) {
>             holder.setFixedSize(mVideoWidth, mVideoHeight);
>
>         }
>
>     }
>
>     public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int 
> k) {
>         Log.d(TAG, "surfaceChanged called");
>
>     }
>
>     public void surfaceDestroyed(SurfaceHolder surfaceholder) {
>         Log.d(TAG, "surfaceDestroyed called");
>     }
>
>     public void surfaceCreated(SurfaceHolder holder) {
>         // TODO Auto-generated method stub
>         Log.d(TAG, "surfaceCreated called");
>         playVideo(extras.getInt(MEDIA));
>
>     }
>
>     @Override
>     protected void onDestroy() {
>         super.onDestroy();
>         // TODO Auto-generated method stub
>         if (mMediaPlayer != null) {
>             mMediaPlayer.release();
>             mMediaPlayer = null;
>         }
>
>     }
>
> }
>
> 在2009-03-04,zypsg <zhaoyongp...@gmail.com> 写道:
>
>
>
> >Hi, A surprising problem occurs when I try to play Video, I can only
> >hear the sound part of the video. My code snippet is below:
>
> >public class VideoDemo extends Activity {
>
> >    public static final int MENU_PLAYER=Menu.FIRST;
> >    public static final int MENU_VIDEO=MENU_PLAYER+1;
> >    private final static String VIDEOURL="/sdcard/10-58-26.3gp";
> >    /** Called when the activity is first created. */
> >    @Override
> >    public void onCreate(Bundle savedInstanceState) {
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.main);
> >      //  playVideoByVideoView(VIDEOURL);
> >    }
> >    private void playVideoByVideoView(String fileURL){
> >//          this.getWindow().setFormat(PixelFormat.TRANSLUCENT);
> >            setContentView(R.layout.videoview);
> >            VideoView videoView=(VideoView)findViewById(R.id.surface_view);
>
> >//          videoView.setVisibility(SurfaceView.VISIBLE);
> >            videoView.bringToFront();
> >            videoView.setVideoPath(fileURL);
> >            videoView.setMediaController(new MediaController(this));
> >            videoView.requestFocus();
> >//          videoView.start();
> >    }
> >    private void playVideoByMediaPlayer(String fileURL){
> >            MediaPlayer mp = new MediaPlayer();
> >            SurfaceView sv =new SurfaceView(this);
> >            try {
> >                    mp.setDataSource(fileURL);
> >                    mp.setDisplay(sv.getHolder());
> >                    mp.prepare();
> >                    mp.start();
> >            } catch (IllegalArgumentException e) {
> >                    // TODO Auto-generated catch block
> >                    e.printStackTrace();
> >                    mp.release();
>
> >            } catch (IllegalStateException e) {
> >                    // TODO Auto-generated catch block
> >                    e.printStackTrace();
> >                    mp.release();
> >            } catch (IOException e) {
> >                    // TODO Auto-generated catch block
> >                    e.printStackTrace();
> >                    mp.release();
> >            }
> >    }
> >    @Override
> >    public boolean onCreateOptionsMenu(Menu menu) {
> >            // TODO Auto-generated method stub
> >            boolean ret= super.onCreateOptionsMenu(menu);
> >            menu.add(0, MENU_PLAYER, 0, "MediaPlayer");
> >            menu.add(0, MENU_VIDEO, 0, "VideoView");
> >            return ret;
> >    }
> >    @Override
> >    public boolean onMenuItemSelected(int featureId, MenuItem item) {
> >            // TODO Auto-generated method stub
> >            boolean ret= super.onMenuItemSelected(featureId, item);
> >            switch(item.getItemId()){
> >            case MENU_PLAYER:
> >                    playVideoByMediaPlayer(VIDEOURL);
>
> >                    break;
> >            case MENU_VIDEO:
> >                    playVideoByVideoView(VIDEOURL);
> >                    break;
> >            }
> >            return ret;
> >    }
> >}
>
> >But when I invoke playVideoByVideoView() method in onCreate() ,I can
> >see the video part.  Can anybody tell me why this problem happen?  How
> >can I solve this problem. Thanks Very Much!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to