开发者社区> 问答> 正文

android阿里云点播无法响应OnCompletionListener

不添加TextureRenderView,或者SurfaceRenderView,就无法响应OnCompletionListener。为什么呢?

展开
收起
游客hua3llcijzmum 2021-01-06 11:07:00 861 0
1 条回答
写回答
取消 提交回答
  • 下一站是幸福

    下面是我的伪代码

    private void playVideo() { //如果不为空释放在new if (mediaPlayer != null) { mediaPlayer.reset(); } mediaPlayer = new MediaPlayer(); try { mediaPlayer.setDataSource(getContext(), Uri.parse(videoUrl)); if (mSurfaceView.getVisibility() == View.GONE) mSurfaceView.setVisibility(View.VISIBLE); SurfaceHolder holder = mSurfaceView.getHolder(); holder.addCallback(new MyCallBack()); mediaPlayer.prepare(); //准备完成监听 mediaPlayer.setOnPreparedListener(onPreparedListener); mediaPlayer.setOnCompletionListener(onCompletionListener); } catch (Exception e) { e.printStackTrace(); } }

    /**
     * 准备完成
     */
    MediaPlayer.OnPreparedListener onPreparedListener = new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
    

    // mediaPlayer.setLooping(true);//循环播放 mp.start(); } };

    MediaPlayer.OnCompletionListener onCompletionListener = new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            XLogUtils.e("播放完成");
            mSurfaceView.setVisibility(View.GONE);
            if (currentVideoIndex == videoUrls.size() - 1) return;
            currentVideoIndex++;
            videoUrl = videoUrls.get(currentVideoIndex);
            XLogUtils.d("播放下一个");
            playVideo();
        }
    };
    
    /**
     *
     */
    private class MyCallBack implements SurfaceHolder.Callback {
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            if (mediaPlayer != null)
                mediaPlayer.setDisplay(holder);
        }
    
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    
        }
    
        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
    
        }
    }
    

    7 4

    2021-04-02 22:08:25
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载