[考试]的Android Videoview只能使用本地文件 [英] [Java]Android Videoview works only with local files
本文介绍了[考试]的Android Videoview只能使用本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从URL播放视频,但只有本地视频作品在我的code。如果我尝试从URL我的Nexus 7显示屏打开视频
无法播放这部影片。这里是code本地文件的播放,它工作正常(两者是相同的视频)
I tried to play a video from a url, but only local videos works in my code. If I try to open a video from a url my nexus 7 displays Can not play this video. Here is the code for the playback of a local file, it works fine (both are the same videos)
package com.sample.prog;
import java.io.File;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.VideoView;
import android.net.Uri;
public class MainActivity extends Activity {
static private final String pathToFile = "bigbuck.mp4";
private VideoView videoPlayer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
File root = Environment.getExternalStorageDirectory();
videoPlayer = (VideoView) findViewById(R.id.videoPlayer);
videoPlayer.setKeepScreenOn(true);
videoPlayer.setVideoPath(root + "/" + pathToFile);
videoPlayer.start();
}
}
和这里是code从一个url视频的播放,但它不工作
and here is the code for the playback of video from a url, but it don't work
package com.sample.prog;
import java.io.File;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.VideoView;
import android.net.Uri;
public class MainActivity extends Activity {
static private final String pathToFile = "http://www.myanimesource.de/bigbuck.mp4";
private VideoView videoPlayer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//File root = Environment.getExternalStorageDirectory();
videoPlayer = (VideoView) findViewById(R.id.videoPlayer);
videoPlayer.setKeepScreenOn(true);
videoPlayer.setVideoPath(URI.parse(pathToFile));
videoPlayer.start();
}
}
希望你能帮助我解决我的问题,
hope you can help me to solve my problem,
问候
基督教
推荐答案
请确保您有互联网接入正确的权限;把下面的行你的AndroidManifest.xml:
Make sure you have the correct permissions for internet access; put the following lines in your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
这篇关于[考试]的Android Videoview只能使用本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文