Search code examples
javaandroidvideostreaminghttp-live-streaming

Android app says: "Can't Play This Video." when playing HTTP Live Stream on Android


I'm trying to create a little Android app that plays a HTTP Live Streaming (HLS) video encoded in H.264 / MP4.

When I launch this app on my device, it says:

Can't Play This Video.

The device is a Galaxy S3 running Android 4.1.2. Here is my code:

package com.florianjensen.FlorianTest;

import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
import android.net.Uri;

public class MyActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
        String httpLiveUrl = 
            "http://ds4178.flosoft-servers.net:1935/flosoft/" +
            "mp4:twitStream_1128/playlist.m3u8";

        myVideoView.setVideoURI(Uri.parse(httpLiveUrl));
        myVideoView.setMediaController(new MediaController(this));
        myVideoView.requestFocus();
        myVideoView.start();
    }
}

What causes that error?


Solution

  • You have to give the app Permission to use the Internet in the app's Manifest so that the program knows to warn the user what features you plan to utilize. It is also a way users can select apps on the android play store based on which one uses internet and which ones do not.

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

    Place the above uses-permission tag inside of the manifest tag:

    <manifest xlmns:android...>
    
    </manifest>
    

    As soon as you add this, it should work. For more instructions on exactly how to place this tag: http://developer.android.com/guide/topics/security/permissions.html