make ready layout for playback image follow:
make ready surface callback follow:
@Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } @Override public void surfaceCreated(SurfaceHolder holder) { } @Override public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub }First I create surface view.
_preview = (SurfaceView)findViewById(R.id.surfaceView1); _holder = _preview.getHolder(); _holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); _holder.addCallback(this);
Second If surfaceCreated call, start to play clip.
String path = "/sdcard/sample.mp4"; _mediaplayer = new MediaPlayer(); try { _mediaplayer.setDataSource(path); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } _mediaplayer.setDisplay(holder); try { _mediaplayer.prepare(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } _mediaplayer.setOnPreparedListener(this);
Last If end prepare(), onPrepared called.
@Override public void onPrepared(MediaPlayer mp) { // TODO Auto-generated method stub _mediaplayer.start(); }
source code here
0 件のコメント:
コメントを投稿