Android剪切长视频并分别获取视频片段

时间:2016-07-21 00:07:37

标签: android video android-mediaplayer android-videoview video-editing

我想从长视频中剪辑2到3分钟。到目前为止,我只能使用videoView播放长视频。

// Set the media controller buttons
if(mediaController ==null){
    mediaController = new MediaController(VideoActivity.this);

    // Set the videoView that acts as the anchor for the MediaController.
    mediaController.setAnchorView(mVideoView);

    // Set MediaController for VideoView
    mVideoView.setMediaController(mediaController);
}

try {
    // ID of video file.
    int id = this.getRawResIdByName("kung_fu_panda_3");
    mVideoView.setVideoURI(Uri.parse("android.resource://" + mContext.getPackageName() + "/" + id));

} catch (Exception e) {
    Log.e("Error", e.getMessage());
    e.printStackTrace();
}

mVideoView.requestFocus();

// When the video file ready for playback.
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

    public void onPrepared(MediaPlayer mediaPlayer) {

        mVideoView.seekTo(position);
        if (position == 0) {
            mVideoView.start();
        }

        // When video Screen change size.
        mediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
            @Override
            public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {

                // Re-Set the videoView that acts as the anchor for the MediaController
                mediaController.setAnchorView(mVideoView);
            }
        });
    }
});

0 个答案:

没有答案