在使用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. ...
Estimating the surface area and volume of ellipsoidal ham using computer vision
Effect of the molecular weight of sizing agent on the surface of carbon fibres and interface of its composites
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 ...
机工2班-17组原文Influence of pores on the surface microcompression mechanical response
An ExcelTM spreadsheet program for reconstructing the surface profile of former mountain glaciers and ice caps
微软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 ✖ ...
The elementary steps of the methanol synthesis reaction at oxygen vacancies on the polar ZnO(000¯1) surface have been studied with density functional theory. We report results for reaction and ...
has been reinforced, and its attack surface has been considerably reduced by aggressively decreasing the number of system processes that run as root. In addition to these exploit mitigations, recent ...
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 ...
LDA2Net Digging under the surface of COVID-19 topics in scientific literature_科学文献2019冠状病毒疾病挖掘.pdf
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 ...
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 ...