Skip to content

Instantly share code, notes, and snippets.

@kswlee
Created May 22, 2013 13:45
Show Gist options
  • Select an option

  • Save kswlee/5627632 to your computer and use it in GitHub Desktop.

Select an option

Save kswlee/5627632 to your computer and use it in GitHub Desktop.

Revisions

  1. kswlee created this gist May 22, 2013.
    37 changes: 37 additions & 0 deletions android mediaplayer use textureview
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    public VideoFrameExtractor(Context context, String path, TextureView textureView) {
    mVideoPath = path;
    mTextureView = textureView;

    textureView.setSurfaceTextureListener(this);
    textureView.setTranslationX(-1920);

    if (textureView.isAvailable()) {
    initPlayer(textureView.getSurfaceTexture());
    }
    }

    private void initPlayer(SurfaceTexture surfaceTexture) {
    mPlayer = new MediaPlayer();
    Surface surface = new Surface(surfaceTexture);

    try {
    mPlayer.setDataSource(mVideoPath);
    mPlayer.setSurface(surface);
    mPlayer.prepare();

    extractFrames();
    //mPlayer.start();
    } catch (IllegalArgumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (SecurityException 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();
    }
    }