我有一个 mp4 视频,我尝试在 TextureView 中播放我的视频。
我有一个问题。在 Nexus 或 HTC 中,我没有问题,但在某些华为设备中,我有此消息
Unable To create Media player
这是我的来源
private void playVideoAnimation()
{
textureView.setVisibility(View.VISIBLE);
mMediaPlayer = new MediaPlayer();
textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
Surface surface = new Surface(surfaceTexture);
try {
Log.e("FILE_NAME", FILE_NAME);
AssetFileDescriptor afd = getAssets().openFd(FILE_NAME);
mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
mMediaPlayer.setSurface(surface);
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
if (mediaPlayer.isPlaying()) {
}
mediaPlayer.start();
}
});
mMediaPlayer.prepareAsync();
} catch (IllegalArgumentException e) {
Log.d(TAG, e.getMessage());
} catch (SecurityException e) {
Log.d(TAG, e.getMessage());
} catch (IllegalStateException e) {
Log.d(TAG, e.getMessage());
} catch (IOException e) {
Log.d(TAG, e.getMessage());
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
});
mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.e("FILE_NAME", "Finished");
}
});
}
正如我所说,我可以在 Nexus 和 HTC 设备上播放我的视频,但昨天我在华为运行我的应用程序,我收到了这个错误消息。
我如何检查设备是否可以播放视频?
如果有人知道解决方案,请帮助我