在使用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已经做的很好了,自己再写这些确实费力,期望以后扩展会好点
分享到:
相关推荐
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) 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 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
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 ...
纳米硅线的声子色散关系及热导:原子配位缺陷效应,孙长庆,,The effect of bond-order losses due to the surface on the thermal conductivity of cylindrical silicon nanowires has been examined using the ...
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. ...
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 Book - Blue 3500 ✖ 2333 Surface Book - Rainbow 3000 ✖ 2000 Surface Book - Red 2500 ✖ 1667 Surface Book - Yellow 2500 ✖ 1666 Surface Family 2050 ✖ ...
An ExcelTM spreadsheet program for reconstructing the surface profile of former mountain glaciers and ice caps
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 ...
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 ...
Surfacer 11是一款强大的三维逆向工程软件,它专为设计师和工程师们提供了高效、精准的3D建模工具。在这款中文版本中,用户可以享受到更加友好的操作界面和全面的功能,使得复杂的逆向工程过程变得更加简单易懂。 ...
标题“机工2班-17组原文Influence of pores on the surface”和描述“机工2班-17组原文Influence of pores on the surface microcompression mechanical response”均指向同一主题,即孔隙对表面微观压缩机械响应的...
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 ...
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是一款强大的三维建模和表面设计软件,主要应用于工业设计、汽车造型、航空制造、游戏开发以及影视特效等领域。它以其高效的曲面建模工具和直观的用户界面,深受专业设计师和艺术家的喜爱。这款软件的中文...
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 ...
标题中的“Surface RT 9月越狱脚本”指的是针对微软Surface RT设备的越狱工具,这个工具在2019年9月发布,目的是为了突破Surface RT操作系统的限制,从而能够安装非官方市场提供的桌面应用程序。Surface RT是微软...