视频在下面提到的代码中无法正常工作。这可能是什么问题?
MediaController mediaController = new MediaController(getBaseContext());
mediaController.setAnchorView(videoweb);
Uri video = Uri.parse("http://www.youtube.com/v/wwI2w2YHkCQ?fs=1");
videoweb.setMediaController(mediaController);
videoweb.setVideoURI(video);
videoweb.start();
错误:
无法播放视频
抱歉,此视频无法播放。
答案 0 :(得分:6)
您提供的链接http://www.youtube.com/v/wwI2w2YHkCQ?fs=1
用于HTML页面。要为setVideoURI()
提供的URI应为媒体文件,例如MP4或AVI。
VideoView无法解析HTML页面。它只能解码和播放视频文件或流式传输视频内容(在这种情况下,URI应指向媒体文件,例如http://people.sc.fsu.edu/~jburkardt/data/mp4/cavity_flow_movie.mp4
)。请参阅Stack Overflow问题 Using VideoView for streaming or progressive-download video 。
您应该使用Webview打开YouTube链接。
答案 1 :(得分:2)
VideoView
和Mediaplayer
只能播放文档中提供的格式 Android Supported Media Formats 。
您提供的YouTube视频链接适用于 HTML网页。如果你正在播放Karthik所提到的HTML页面,最好使用Webview
。
String url = "your_youtube_link";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
如果您只想从该链接查看视频,请在页面中保留所有其他详细信息。假设这是YouTube链接http://www.youtube.com/watch?v=ZC7ZOGpM2cU&feature=g-logo&context=G233b464FOAAAAAAABAA
如果您解析YouTube HTML页面的来源,您可能会看到以下部分:
<link rel="alternate" type="application/json+oembed" href="http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3DZC7ZOGpM2cU&format=json" title="Bigg Boss 5: Juhi Parmar wins Big Boss season 5">
<link rel="alternate" type="text/xml+oembed" href="http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3DZC7ZOGpM2cU&format=xml" title="Bigg Boss 5: Juhi Parmar wins Big Boss season 5">
<meta property="fb:app_id" content="87741124305">
<meta property="og:url" content="http://www.youtube.com/watch?v=ZC7ZOGpM2cU">
<meta property="og:title" content="Bigg Boss 5: Juhi Parmar wins Big Boss season 5">
<meta property="og:description" content="Ntv News: Juhi Parmar wins Bigg Boss 5 - Juhi Parmar wins 'Bigg Boss 5', takes home Rs.1 crore - No kid for now, keen for good work: Juhi Parmar">
<meta property="og:type" content="video">
<meta property="og:image" content="http://i3.ytimg.com/vi/ZC7ZOGpM2cU/hqdefault.jpg">
<meta property="og:video" content="http://www.youtube.com/v/ZC7ZOGpM2cU?version=3&autohide=1">
<meta property="og:video:type" content="application/x-shockwave-flash">
<meta property="og:video:width" content="396">
<meta property="og:video:height" content="297">
<meta property="og:site_name" content="YouTube">
在此,提取以下内容
<meta property="og:video" content="http://www.youtube.com/v/ZC7ZOGpM2cU?version=3&autohide=1">
在此,<http://www.youtube.com/v/ZC7ZOGpM2cU?version=3&autohide=1>
链接会全屏显示。
答案 2 :(得分:1)
实际上,为了播放我正在使用的任何流媒体视频
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/v/wwI2w2YHkCQ?fs=1")));
但我不认为这对你的链接有用。最好试试
mediaplayer.setdataSource("your link").
答案 3 :(得分:1)
好的,请尝试以下代码。它会起作用。
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.youtube.com/v/wwI2w2YHkCQ?fs=1"));
startActivity(i);
答案 4 :(得分:0)
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mVideoView = (VideoView) findViewById(R.id.surface_view);
}
private void playVideo() {
try {
final String path = "http://www.youtube.com/v/wwI2w2YHkCQ?fs=1"
System.out.println("path "+path);
Log.v(TAG, "path: " + path);
if (path == null || path.length() == 0) {
Toast.makeText(VideoViewDemo.this, "File URL/path is empty",
Toast.LENGTH_LONG).show();
}
else {
System.out.println("else ");
// If the path has not changed, just start the media player
if (path.equals(current) && mVideoView != null) {
System.out.println("mVideoView.start() ");
mVideoView.start();
mVideoView.requestFocus();
return;
}
current = path;
//mVideoView.setVideoPath(getDataSource(path));
mVideoView.setVideoURI(Uri.parse(path));
mVideoView.start();
mVideoView.requestFocus();
}
}
catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
if (mVideoView != null) {
mVideoView.stopPlayback();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText android:id="@+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<ImageButton android:id="@+id/play"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/play"/>
<ImageButton android:id="@+id/pause"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/pause"/>
<ImageButton android:id="@+id/reset"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/reset"/>
<ImageButton android:id="@+id/stop"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/stop"/>
</LinearLayout>
<VideoView android:id="@+id/surface_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</VideoView>
</LinearLayout>