gpt4 book ai didi

android - 某些视频格式不适用于 mediaPlayer

转载 作者:行者123 更新时间:2023-11-30 01:07:15 24 4
gpt4 key购买 nike

我使用 mediaPlayer 和 surfaceView 来读取这样的视频:

   mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);

mMediaPlayer.setDataSource(this, uriVideo);
mMediaPlayer.prepare();
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {

}

@Override
public void onPrepared(MediaPlayer mp) {
mMediaPlayer.start();
}

问题,有些类型的视频(.avi、.mkv、...)在这个播放器上不工作,同样的视频在其他视频播放器上工作,比如 VLC 播放器;我得到这个错误

java.io.IOException: setDataSource failed.: status=0x80000000
at android.media.MediaPlayer._setDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1113)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1070)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1009)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:956)
at com.geniussecurity.pleo.VideoActivity.surfaceCreated(VideoActivity.java:385)
at android.view.SurfaceView.updateWindow(SurfaceView.java:583)
at android.view.SurfaceView.access$000(SurfaceView.java:88)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:177)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1880)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1006)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5652)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5426)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)

请帮忙。

最佳答案

检查 Supported Media Formats在使用 MediaPlayer 之前。

VLC 和其他播放器使用它们自己的原生层来解码和播放视频。

可以尝试使用一些基于ffmpeg的视频播放库:

  1. jkplayer
  2. AndroidFFmpeg

关于android - 某些视频格式不适用于 mediaPlayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38765601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com