`
dingran
  • 浏览: 376165 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

The surface has been released 异常

阅读更多

在使用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已经做的很好了,自己再写这些确实费力,期望以后扩展会好点

 

分享到:
评论
8 楼 qzrsqzrsqzrs 2016-09-02  
7 楼 u011262505 2015-03-17  
纳尼,我发现我还是有这个问题
6 楼 Evilover3 2013-03-12  
请问一下,我是直接使用videoView,然后将整个view加载到WindowManager中,然后就提示这个log,请问是怎么弄呢?
5 楼 dingran 2013-02-06  
aduo_vip 写道
请问
这里  surfaceHolder 跟mediaPlayer 没有关联吗?

mediaPlayer.setDisplay() 写在哪个地方呢


surfaceHolder = surfaceView.getHolder();
        surfaceHolder.addCallback(this);



      mediaPlayer.setDisplay(surfaceHolder);

这就是他们的关系和顺序啊。
4 楼 yye_javaeye 2013-02-05  
不能解决啊,这个代码当处在一个activity里时,addCallback()里面放什么呢?
3 楼 dadoneo 2012-07-09  
这是在SurfaceView继承类里边写的还是在Activity里边写的,此问题困扰我很久了,按LZ方法仍是不行啊,创建surface时返回空值
2 楼 dingran 2012-04-12  


aduo_vip 写道
请问
这里  surfaceHolder 跟mediaPlayer 没有关联吗?

mediaPlayer.setDisplay() 写在哪个地方呢



不好意思,少了点东西,应该是在addCallBack后设置:

mediaPlayer.setDisplay(surfaceHolder);

就是这个public void setDisplay(SurfaceHolder sh)
1 楼 aduo_vip 2012-03-31  
请问
这里  surfaceHolder 跟mediaPlayer 没有关联吗?

mediaPlayer.setDisplay() 写在哪个地方呢

相关推荐

    The Rh influence on the surface distribution of the ternary alloy Pt-Pd-Rh

    The Rh influence on the surface distribution of the ternary alloy Pt-Pd-Rh,陈羽,,Using the modified analytical embedded atom method (MAEAM) and combining with Monte Carlo computer simulation, the ...

    FVFOM: A three dimensional semi-implicit unstructured grid ocean model

    (FVFOM) has been developed for simulating the coastal ocean circulation, which is based on staggered C-unstructured non-orthogonal grid in the horizontal direction and Z-level grid in the vertical ...

    Cylindrical Grinding - A Review on Surface Integrity

    Cylindrical grinding is one of the important metal cutting processes used ... This review may have been planned to be useful to the researchers and other professionals interested to work on grinding

    The Concept of a Riemann Surface

    The Concept of a Riemann Surface The Concept of a Riemann Surface

    Blending of the Landsat and MODIS Surface Reflectance

    On the Blending of the Landsat and MODIS Surface Reflectance: Predicting Daily Landsat Surface Reflectance; Data fusion, image enhancement, image processing, Landsat, Moderate Resolution Imaging ...

    Impact of surface-bond-order-loss on the phonon dispersion relations and the thermal conductivity of cylindrical silicon nanowires

    纳米硅线的声子色散关系及热导:原子配位缺陷效应,孙长庆,,The effect of bond-order losses due to the surface on the thermal conductivity of cylindrical silicon nanowires has been examined using the ...

    rbf在滑模控制中的应用SCI资料

    mode control, a radial basis functions (RBF) neural network control algorithm has been introduced to offset the disadvantage of the sliding mode control by moving the sliding surface effectively. ...

    Linux Device Driver 3rd Edition

    This is, on the surface, a book about writing device drivers for the Linux system. That is a worthy goal, of course; the flow of new hardware products is not likely to slow down anytime soon, and ...

    微软Surface系列壁纸(共19张)

    微软Surface系列壁纸(共19张)超高清壁纸 Surface Book - Blue 3500 ✖ 2333 Surface Book - Rainbow 3000 ✖ 2000 Surface Book - Red 2500 ✖ 1667 Surface Book - Yellow 2500 ✖ 1666 Surface Family 2050 ✖ ...

    reconstructing the ice surface profile

    An ExcelTM spreadsheet program for reconstructing the surface profile of former mountain glaciers and ice caps

    The A-buffer, an Antialiased Hidden Surface Method (1984)

    The A-buffer (anti-aliased, area-averaged, accumulation buffer) is a general hidden surface mechanism suited to medium scale virtual memory computers. It resolves visibility among an arbitrary ...

    Linux设备驱动第三版

    This is, on the surface, a book about writing device drivers for the Linux system. That is a worthy goal, of course; the flow of new hardware products is not likely to slow down anytime soon, and ...

    surfacer11中文版

    Surfacer 11是一款强大的三维逆向工程软件,它专为设计师和工程师们提供了高效、精准的3D建模工具。在这款中文版本中,用户可以享受到更加友好的操作界面和全面的功能,使得复杂的逆向工程过程变得更加简单易懂。 ...

    机工2班-17组原文Influence of pores on the surface

    标题“机工2班-17组原文Influence of pores on the surface”和描述“机工2班-17组原文Influence of pores on the surface microcompression mechanical response”均指向同一主题,即孔隙对表面微观压缩机械响应的...

    The c++ programming language.azw3

    The brand-new edition of the worlds most trusted and widely read guide to C++, it has been comprehensively updated for the long-awaited C++11 standard. Extensively rewritten to present the C++11 ...

    ICONE27-1981_surface_airentrapment_droplet_

    Spray system has been used to lower the containment temperature and pressure and prevent the release of the fission products in Pressurized Water Reactors. Single droplet impingement on the solid ...

    Surfacer11中文版

    Surfacer11是一款强大的三维建模和表面设计软件,主要应用于工业设计、汽车造型、航空制造、游戏开发以及影视特效等领域。它以其高效的曲面建模工具和直观的用户界面,深受专业设计师和艺术家的喜爱。这款软件的中文...

    2013 Stroustrup - The C++ Programming Language 4th Edition.zip

    The brand-new edition of the worlds most trusted and widely read guide to C++, it has been comprehensively updated for the long-awaited C++11 standard. Extensively rewritten to present the C++11 ...

    SurfaceRT 9月越狱脚本

    标题中的“Surface RT 9月越狱脚本”指的是针对微软Surface RT设备的越狱工具,这个工具在2019年9月发布,目的是为了突破Surface RT操作系统的限制,从而能够安装非官方市场提供的桌面应用程序。Surface RT是微软...

Global site tag (gtag.js) - Google Analytics