2017-10-19 406 views
1

我無法讓播放器播放所有m3u8播放列表。沒有任何問題,直接鏈接到MP4文件播放。我找到的只有1-2個m3u8文件可以播放(其中之一是:http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8)。但所有其他m3u8播放列表不起作用。例如:該播放列表http://62.6.220.50:8000/playlist.m3u8劇本沒有在瀏覽器中的問題,但在Android Studio中會產生錯誤:VideoView不會播放m3u8文件

«Can’t play this video» 

,並在日誌中以下錯誤:

«E/MediaPlayer: error (1, -1007) D/VideoView: Error: 1,-1007». 

我在做什麼錯?我怎樣才能讓玩家可以毫無問題地播放m3u8文件。也許我必須預先解析這個播放列表,然後才能播放它。請告訴我,我該如何解決這個問題。這裏是我的代碼:

清單:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.INTERNET"/> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:roundIcon="@mipmap/ic_launcher_round" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

ACTIVITY_MAIN:

<VideoView 
    android:id="@+id/myVideoView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:visibility="visible" 
    tools:layout_editor_absoluteY="0dp" 
    tools:layout_editor_absoluteX="-315dp" /> 

MAINACTIVITY:

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import java.net.URL; 
import android.net.Uri; 
import android.os.Bundle; 
import android.widget.MediaController; 
import android.widget.VideoView; 

public class MainActivity extends AppCompatActivity { 
    private String urlStream; 
    private VideoView myVideoView; 
    private URL url; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     myVideoView = (VideoView)this.findViewById(R.id.myVideoView); 
     MediaController mc = new MediaController(this); 
     myVideoView.setMediaController(mc); 
     urlStream = "http://62.6.220.50:8000/playlist.m3u8"; 
     //urlStream = "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"; 
     //urlStream = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4"; 

     runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
       myVideoView.setVideoURI(Uri.parse(urlStream)); 
      } 
     }); 
    } 
} 
+0

親愛的Artem,請花幾分鐘時間遵循 的說明https://stackoverflow.com/help/how-to-ask – ViKiNG

回答

0

的Android已與HLS問題的歷史流 - 我想,這大概是公平地說,ExoPlayer是一種更可靠的方式來播放HLS:

如果你看一下上面鏈接當前開發人員指南,它給它支持這些已經超出了在MediaPlayer的正規的一些HLS功能的示例:

  • Support for advanced HLS features, such as correct handling of #EXT-X-DISCONTINUITY tags.
相關問題