Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

视频录制完成之后,播放视频 #20

Closed
NewBrandSTONE opened this issue Sep 13, 2017 · 1 comment
Closed

视频录制完成之后,播放视频 #20

NewBrandSTONE opened this issue Sep 13, 2017 · 1 comment

Comments

@NewBrandSTONE
Copy link

您好,我想向您咨询一下,视频录制完成后,如果进行播放视频操作的思路。

我直接在MediaUtils的stopRecordSave方法中声明MediaPlayer并且用来播放之前录制的视频,但是一直不成功,提示状态不对,请问您知道什么方法去解决这个问题吗?

感谢!

@NewBrandSTONE
Copy link
Author

我这里想出了一个解决办法,不知道对不对,效果是有了

在MediaUtil中编写方法

public void stopPreview() {
      releaseCamera();
}

在VideoRecordActivity的stopView方法,增加initPlayer方法

private void stopView(boolean isSave) {
        stopAnim();
        progressBar.setCancel(true);
        mProgress = 0;
        handler.removeMessages(0);
        btnInfo.setText("双击放大");
        if (isSave) {
            recordLayout.setVisibility(View.GONE);
            send.startAnim();
             // 释放摄像头资源
            mediaUtils.stopPreview();
            // 播放之前录制的视频
            initPlayer();
        }
    }

initPlayer方法

private void initPlayer() {
        // 必须在surface创建后才能初始化MediaPlayer,否则不会显示图像
        mPlayer = new MediaPlayer();
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mSurfaceHolder = surfaceView.getHolder();
        mPlayer.setDisplay(mSurfaceHolder);
        // 循环播放
        mPlayer.setLooping(true);
        // 设置显示视频显示在SurfaceView上
        try {
            mPlayer.setDataSource(mediaUtils.getTargetFilePath());
            mPlayer.prepare();
            mPlayer.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant