没有videoview的Android播放视频按钮[解决] [英] Android play video button without videoview [Resolved]
问题描述
我有一个简单的按钮,我想这个按钮,但没有一个 videoView
发挥URL视频点击购买。
所以,如果我按一下按钮,手机将询问其内部球员,我会选择要播放的视频。
I have a simple button, and I wish to play an URL video buy clicking on this button but without a videoView
.
So if I click on the button , the phone will ask which internal player I'll choose to play the video.
在这里,我使用的是 videoView
正在播放我的应用程序的窗口里面的视频,但我想外面是:
Here I was using a videoView
that was playing the video inside the window of my application but I want it outside :
boutonVideo = (Button) findViewById(R.id.boutonVideo);
video = (VideoView) findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video);
video.setMediaController(mediaController);
Uri chemin = Uri.parse("http://commonsware.com/misc/test2.3gp");
video.setVideoURI(chemin);
video.start();
感谢您,
所以这里的code:
boutonVideo = (Button) findViewById(R.id.boutonVideo);
boutonVideo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent in;
if (v.getId() == R.id.boutonVideo) {
in = new Intent(Intent.ACTION_VIEW, Uri
.parse(urlBandeAnnonce));
startActivity(in);
}
}
});
但它返回我一个错误,当我决定要停止视频并返回到我的活动。
这里是AndroidRunTime错误:
But it return me an error when I decide to stop the video and return to my activity. Here is the AndroidRunTime Error :
了java.lang.RuntimeException:无法启动活动
ComponentInfo {}活动:显示java.lang.NullPointerException
09-30 15:20:16.449:E / AndroidRuntime(2301):结果
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
java.lang.RuntimeException: Unable to start activity ComponentInfo{Activity}: java.lang.NullPointerException 09-30 15:20:16.449: E/AndroidRuntime(2301):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
所以我添加完成();和误差消失。
So I add finish(); and the error disappear.
推荐答案
使用的意图
与 ACTION_VIEW
随该URI的电影你要玩:
Use an Intent
with ACTION_VIEW
along with the URI to the movie you want to play:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
startActivity(intent);
其中, movieUrl
是包含路径电影的字符串。
where movieUrl
is a string containing the path to the movie.
这可能会或可能不会与互联网流工作。不能很好地与亲自尝试过。
This may or may not work with internet streams. Haven't tried it with those personally.
这篇关于没有videoview的Android播放视频按钮[解决]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!