Я пытаюсь воспроизвести локальный файл m3u8, который хранится в моей sdcard, используя класс mediaplayer для Android. Файлы m3u8 и .ts находятся в одном каталоге. Сторонние игроки, такие как MXPlayer, присоединяются к файлам ts и воспроизводят видео, когда я открываю m3u8. Но использование класса mediaplayer для android вызывает следующую ошибку:
Невозможно создать медиаплеер Ошибка: setDataSourceFD failed: status = 0x80000000 java.io.IOException: сбой setDataSourceFD: status = 0x80000000 на android.media.MediaPlayer.setDataSource(собственный метод) на android.media.MediaPlayer.setDataSource(MediaPlayer.java:1204) на com.tcs.hlsvideo.StreamingPlayer.playVideo(StreamingPlayer.java:87) на com.tcs.hlsvideo.StreamingPlayer.surfaceCreated(StreamingPlayer.java:148) на android.view.SurfaceView.updateWindow(SurfaceView.java:609) на android.view.SurfaceView.access $000 (SurfaceView.java:86) на android.view.SurfaceView $3.onPreDraw(SurfaceView.java:178) в android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:707) на android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1981) в android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1143) at android.view.ViewRootImpl $TraversalRunnable.run(ViewRootImpl.java:4667) на android.view.Choreographer $CallbackRecord.run(Хореограф.ява: 725) на android.view.Choreographer.doCallbacks(Хореограф .java:555) на android.view.Choreographer.doFrame(Хореограф .java:525) на android.view.Choreographer $FrameDisplayEventReceiver.run(Хореограф.ява: 711) на android.os.Handler.handleCallback(Handler.java:615) на android.os.Handler.dispatchMessage(Handler.java:92) на android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4960) в java.lang.reflect.Method.invokeNative(собственный метод) в java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:1038) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) в dalvik.system.NativeStart.main(собственный метод) setDataSourceFD failed: status = 0x80000000
Используемый мной код
private static final String TAG = StreamingPlayer.class.getSimpleName();
private String formatedIpAddress;
private int mVideoWidth;
private int mVideoHeight;
private MediaPlayer mMediaPlayer;
private SurfaceView mPreview;
private SurfaceHolder holder;
private String path;
//private boolean mIsVideoSizeKnown = false;
private boolean mIsVideoReadyToBePlayed = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPreview = new SurfaceView(this);
holder = mPreview.getHolder();
holder.addCallback(this);
setContentView(mPreview);
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
int ipAddress = wifiManager.getConnectionInfo().getIpAddress();
formatedIpAddress = String.format("%d.%d.%d.%d", (ipAddress & 0xff),
(ipAddress >> 8 & 0xff), (ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff));
Log.d(TAG, formatedIpAddress);
}
private void playVideo() {
doCleanUp();
try {
//local m3u8 file
path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ts/prog_index.m3u8";
if (path == "") {
// Tell the user to provide a media file URL.
Toast
.makeText(
this,
"Please edit MediaPlayerDemo_Video Activity,"
+ " and set the path variable to your media file URL.",
Toast.LENGTH_LONG).show();
}
Log.e("PATH", "Path = " + path);
// Create a new media player and set the listeners
mMediaPlayer = new MediaPlayer();
//mMediaPlayer.SET
mMediaPlayer.setDataSource(path);
mMediaPlayer.setDisplay(holder);
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.prepare();
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
Log.e(TAG, e.getMessage());
}
}
public void onBufferingUpdate(MediaPlayer arg0, int percent) {
Log.d(TAG, "onBufferingUpdate percent:" + percent);
}
public void onCompletion(MediaPlayer arg0) {
Log.d(TAG, "onCompletion called");
}
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
Log.v(TAG, "onVideoSizeChanged called");
if (width == 0 || height == 0) {
Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")");
return;
}
//mIsVideoSizeKnown = true;
mVideoWidth = width;
mVideoHeight = height;
//&& mIsVideoSizeKnown
if (mIsVideoReadyToBePlayed ) {
startVideoPlayback();
}
}
public void onPrepared(MediaPlayer mediaplayer) {
Log.d(TAG, "onPrepared called");
mIsVideoReadyToBePlayed = true;
//&& mIsVideoSizeKnown
if (mIsVideoReadyToBePlayed ) {
startVideoPlayback();
}
}
public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
Log.d(TAG, "surfaceChanged called");
}
public void surfaceDestroyed(SurfaceHolder surfaceholder) {
Log.d(TAG, "surfaceDestroyed called");
}
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated called");
playVideo();
}
@Override
protected void onPause() {
super.onPause();
releaseMediaPlayer();
doCleanUp();
}
@Override
protected void onDestroy() {
super.onDestroy();
releaseMediaPlayer();
doCleanUp();
}
private void releaseMediaPlayer() {
if (mMediaPlayer != null) {
mMediaPlayer.release();
mMediaPlayer = null;
}
}
private void doCleanUp() {
mVideoWidth = 0;
mVideoHeight = 0;
mIsVideoReadyToBePlayed = false;
//mIsVideoSizeKnown = false;
}
private void startVideoPlayback() {
Log.v(TAG, "startVideoPlayback");
holder.setFixedSize(mVideoWidth, mVideoHeight);
mMediaPlayer.start();
}
Помогите мне здесь, ребята... `