简体   繁体   English

Android应用程序说:“无法播放此视频。”在Android上播放HTTP Live Stream时

[英]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. 我正在尝试创建一个小的Android应用程序,该应用程序播放以H.264 / MP4编码的HTTP Live Streaming(HLS)视频。

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. 该设备是运行Android 4.1.2的Galaxy S3。 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? 是什么导致该错误?

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. 您必须在应用清单中授予该应用使用Internet的权限,以便该程序知道警告用户您打算使用哪些功能。 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. 这也是用户可以在Android Play商店上选择应用程序的一种方式,基于哪个使用互联网,哪些不使用互联网。

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

Place the above uses-permission tag inside of the manifest tag: 将上面的uses-permission标签放置在manifest标签内:

<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 有关确切放置此标记的更多说明,请访问: http : //developer.android.com/guide/topics/security/permissions.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM