2013-11-23 11 views
10

Ich versuche, eine lokale m3u8 Datei zu spielen, die in meiner SD-Karte mit Android Mediaplayer-Klasse gespeichert wird. Die m3u8 Datei und die .ts-Dateien sind in der gleichen Verzeichnis. Third-Party-Player wie MXPlayer verbinden die ts-Dateien und spielen das Video ab, wenn ich den m3u8 daraus öffne. Aber der Einsatz von Android-Mediaplayer-Klasse führt den folgenden error`Spielen Sie eine lokale m3u8 Datei auf Android zeigt SetDataSourceFD fehlgeschlagen .: status = 0x80000000

Unable to to create media player error: setDataSourceFD failed.: status=0x80000000 java.io.IOException: setDataSourceFD failed.: status=0x80000000 at android.media.MediaPlayer.setDataSource(Native Method) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1204) at com.tcs.hlsvideo.StreamingPlayer.playVideo(StreamingPlayer.java:87) at com.tcs.hlsvideo.StreamingPlayer.surfaceCreated(StreamingPlayer.java:148) at android.view.SurfaceView.updateWindow(SurfaceView.java:609) at android.view.SurfaceView.access$000(SurfaceView.java:86) at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:178) at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:707) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1981) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1143) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4667) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) at android.view.Choreographer.doCallbacks(Choreographer.java:555) at android.view.Choreographer.doFrame(Choreographer.java:525) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4960) at java.lang.reflect.Method.invokeNative(Native Method) at 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) at dalvik.system.NativeStart.main(Native Method) setDataSourceFD failed.: status=0x80000000

Der Code, den ich verwendet habe, ist

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(); 
} 

mich hier Jungs Helfen ... `

+1

u die Lösung gekommen? – Sush

+0

Ich habe das gleiche Problem, hast du etwas Nützliches gefunden? – Alf

Antwort

1

Ich bin nicht sicher , aber sieht aus wie M3U8-Datei ist keine Mediendatei. Es ist ein Play List-Dateiformat. Es bedeutet, dass Sie es analysieren, Pfade von Mediendateien von ihm abrufen und eine der Dateien wiedergeben müssen, die Sie erhalten haben.

Hier ist eine kurze Beschreibung wie das Format http://www.gravlab.com/2013/07/05/what-is-an-m3u8-file/ aussieht.

Um zu erfahren, wie es einen Blick auf diese Antwort, um zu analysieren: Parsing HLS m3u8 file using regular expressions