2

I cannot get the player to play all of the m3u8 playlists. Without any problems, direct links to mp4 files are played. There are only 1-2 m3u8 files I managed to find which could be played (one of them is: http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8). But all the other m3u8 playlists do not work. For example: this playlist http://62.6.220.50:8000/playlist.m3u8 plays without problems in the browser, but in Android Studio it produces an error:

«Can’t play this video»

and in the logs the following errors:

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

What am I doing wrong? How can I make it so that player can play m3u8 files without problems. Maybe I must pre-parse this playlist and only then play it. Tell me, please, how can I solve this problem. Here is my code:

MANIFEST:

<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));
            }
        });
    }
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Artem
  • 21
  • 1
  • 2
  • Dear Artem, please spare few minutes to follow the instruction given at https://stackoverflow.com/help/how-to-ask – ViKiNG Oct 19 '17 at 04:46

1 Answers1

0

Android has had problems with HLS streams historically - I think it is probably fair to say that ExoPlayer is a more reliable way to play back HLS still:

If you look at the current Developer guide linked above, it gives an example of some of the HLS functionality that it supports beyond the regular built in MediaPlayer:

  • Support for advanced HLS features, such as correct handling of #EXT-X-DISCONTINUITY tags.
Mick
  • 24,231
  • 1
  • 54
  • 120