Thank you Megha!  I get it!
But I have another question about the onSurfaceCreate() callback.
When will it be invoked?
if I set the surfaceview's visibility from VISIBLE to GONE, then I set
it from GONE to VISIBLE, will the onSurfaceCreate() callback be
invoked again?
Can you give a sample pause a video when it is playing then open
another video file?
I have no idea how to implements it by mediaplayer+surface or
videoview. I tried lots of times but failed.
Thank you very much!

On Apr 8, 6:19 am, "Megha Joshi" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> This is because the surface is not yet ready for the mediaplayer, please
> call the mediaPlayer initialization code in or after OnSurfaceCreate()
> callback..
>
> Thanks,
> Megha
>
>
>
>
>
> On Mon, Apr 7, 2008 at 9:45 AM, fubin <[EMAIL PROTECTED]> wrote:
>
> > In Sample given by google There is a button to invoke a file.
> >    private void playVideo(Integer Media) {
> >        try {
> >            // If the path has not changed, just start the media
> > player
> >            path = "/data/room.mp4";
>
> >            // Create a new media player and set the listeners
> >            mp = new MediaPlayer();
> >            mp.setDataSource(path);
> >            mp.setDisplay(holder.getSurface());
> >            mp.prepare();
> >            mp.setOnBufferingUpdateListener(this);
> >            mp.setOnCompletionListener(this);
> >            mp.setOnPreparedListener(this);
> >            mp.setAudioStreamType(AudioSystem.STREAM_MUSIC);
> >            Log.d("\n\nCREATE", "mediaplayer");
> >            mp.start();
> >        } catch (Exception e) {
> >            Log.e(TAG, "error: " + e.getMessage(), e);
> >        }
> >    }
>
> >    private OnClickListener mPlayListener = new OnClickListener() {
> >        public void onClick(View v) {
> >            playVideo(extras.getInt(MEDIA));
>
> >        }
> >    };
>
> > When I copy the code directly to onCreate like the following program
> > creshed...:
>
> >    public void onCreate(Bundle icicle) {
> >        super.onCreate(icicle);
> >        setContentView(R.layout.mediaplayer);
> >        mPreview = (SurfaceView) findViewById(R.id.surface);
>
> >        // Set the transparency
> >        getWindow().setFormat(PixelFormat.TRANSPARENT);
> >        // Set a size for the video screen
> >        holder = mPreview.getHolder();
> >        holder.addCallback(this);
> >        try {
> >            // If the path has not changed, just start the media
> > player
> >            path = "/data/room.mp4";
>
> >            // Create a new media player and set the listeners
> >            mp = new MediaPlayer();
> >            mp.setDataSource(path);
> >            mp.setDisplay(holder.getSurface());
> >            mp.prepare();
> >            mp.setOnBufferingUpdateListener(this);
>
> >            mp.setOnCompletionListener(this);
> >            mp.setOnPreparedListener(this);
> >            mp.setAudioStreamType(AudioSystem.STREAM_MUSIC);
> >            Log.d("\n\nCREATE", "mediaplayer");
> >            mp.start();
> >        } catch (Exception e) {
> >            Log.e(TAG, "error: " + e.getMessage(), e);
> >        }
> > }
>
> > There is no error information for debug.
> > Anyone have the same problem?
> > Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to