zoukankan      html  css  js  c++  java
  • The surface has been released 异常

    http://dingran.iteye.com/blog/1442502

    =====================================

    在使用surfaceView和MediaPlayer播放视频的时候出现了一个异常,纠结了很久,经过同事帮助,终于发现了问题的根源。

     

    异常如下:

     

    E/AndroidRuntime( 1765): Caused by: java.lang.IllegalArgumentException: The surface has been released
    E/AndroidRuntime( 1765):     at android.media.MediaPlayer._setVideoSurface(Native Method)
    E/AndroidRuntime( 1765):     at android.media.MediaPlayer.setDisplay(MediaPlayer.java:633)

     

     

    原因是在surfaceHolder还没准备好的时候,我就调用了MediaPlayer的start()方法。

     

    正确的播放流程应该是:

     

            surfaceView = (SurfaceView) findViewById(R.id.PlaySurfaceView);
            surfaceHolder = surfaceView.getHolder();
            surfaceHolder.addCallback(this);

     

          mediaPlayer.setDisplay(surfaceHolder);

     

    try {
                
                mediaPlayer.setDataSource(this, Uri.parse("/sdcard/bianxing.ts"));
                
            } catch (IllegalArgumentException e1) {
                e1.printStackTrace();
            } catch (SecurityException e1) {
                e1.printStackTrace();
            } catch (IllegalStateException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            
            try {
                mediaPlayer.prepare();
            } catch (IllegalStateException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            
            mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
                
                @Override
                public void onPrepared(MediaPlayer mp) {
                    
                    mediaPlayer.start();
                    
                }
            });

     

    这样就可以正常播放了,唉,不容易啊,感谢同事的帮助。

     

    其实对Medialayer的封装来说,VideoView已经做的很好了,自己再写这些确实费力,期望以后扩展会好点


    Meet so Meet. C plusplus I-PLUS....
  • 相关阅读:
    制作Autorun的CD
    Sybase ASE MDA tables 装不上怎么办?
    对于TStringList.Find函数,我有话要说
    HH.exe CHM Operator Command.
    Delphi 7的一些常用的快捷键
    Explain Plan
    在Delphi中的Log
    subst windows下实用的磁盘映射工具
    Excel 2007 如何冻结多行&多列
    LinqToDataTable[转]
  • 原文地址:https://www.cnblogs.com/iplus/p/4467404.html
Copyright © 2011-2022 走看看