Android SDK中 - 媒体播放器的视频由网址 [英] Android SDK - Media Player Video from URL

查看:143
本文介绍了Android SDK中 - 媒体播放器的视频由网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个简单的教程,说明如何加载从URL视频到Android的媒体播放器,但不幸的是,我找不到任何!

I've tried to find a simple tutorial which explains how to load a video from a URL into the android media player but unfortunately I couldn't find any!

我已经试过几件事,试图得到它的工作,但仍然没有运气。

I have tried several things to try get it working but still no luck.

什么是有MediaPlayerActivity从URL只是加载一个视频的最佳方式是什么?

What is the best way to have a MediaPlayerActivity just load a video from a URL?

感谢

编辑:

我曾尝试以下code的建议:

I have tried the following code as suggested:

VideoView videoView = (VideoView) findViewById(R.id.your_video_view);
MediaController mediaController = new MediaController(this); 
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse("url-here"));
videoView.start();

这只是崩溃的时候我去这个活动。

It just crashes when I go to this activity.

推荐答案

您可以使用 VideoView 。下面是一个例子:

You can use a VideoView. Here is an example:

VideoView videoView = (VideoView) findViewById(R.id.videoView);
//Use a media controller so that you can scroll the video contents
//and also to pause, start the video.
MediaController mediaController = new MediaController(this); 
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse(videoUrl));
videoView.start();

修改

您应该提供URI(有一个字符串URL 变量,它具有视频的URL)与此code 乌里.parse(URL)。而且还可以肯定,如果URL是适当的。此外,有你所提供的适当的权限,以您的应用程序,如AkashG建议,(因为它使用互联网,你将需要添加<使用-权限的Andr​​oid:名称=android.permission.INTERNET对&GT ; 在你的应用程序的的Manifest.xml )?最后,你应该定义在您的活动 MediaPlayerActivity 您的应用程序的的Manifest.xml

You should provide the URI (having a String url variable, where it has the url of the video) with this code Uri.parse(url). And also be sure if the url is appropriate. Also, have you provided the appropriate permissions to your app, as AkashG suggested, (since it uses the internet you will need to add <uses-permission android:name="android.permission.INTERNET" > in your app's Manifest.xml)? Finally you should define your activity MediaPlayerActivity in in your app's Manifest.xml

编辑完的

您也可以使用的MediaPlayer 。而Android开发者网站上有一个很好的教程这里

You can also use MediaPlayer. The Android developers site has a good tutorial here.

这篇关于Android SDK中 - 媒体播放器的视频由网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆