Android的code:我有YouTube网址codeD,但我不能发挥出自己的应用程序内的视频 [英] Android Code: I have coded for YouTube URL but I can't play videos inside my app
本文介绍了Android的code:我有YouTube网址codeD,但我不能发挥出自己的应用程序内的视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的Android和我有联系的URL,我的YouTube视频。
I am new to Android and I have linked the URL to my YouTube video.
我创建一个XML格式的网页视图,我已经从Java文件链接的YouTube的网址。
I have created a webview in XML and I have linked the URL of YouTube from Java file.
问题是我不能够发挥在应用程序中的视频。
The problem is I am not able to play the videos inside the app.
package com.coded.sandeep;
@SuppressLint("SetJavaScriptEnabled")
public class YoutubeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.youtube_activity);
Uri uri = Uri.parse("http://www.youtube.com/user/applefruit");
VideoView videoView = (VideoView)findViewById(R.id.youtube_view);
videoView.setMediaController(new MediaController(this));
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
/*webView.setWebViewClient(new VideoViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});*/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.youtube, menu);
return true;
}}
xml文件youtube_activity
xml file youtube_activity
<?xml version="1.0" encoding="utf-8"?>
<VideoView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/youtube_view" />
我不能够与此code打,如果我preSS播放按钮什么也没有发生播放按钮被冻结。
I am not able to play with this code if I press the play button nothing is happening play button is frozen.
推荐答案
试试这个简单的code。
Try with this simple code.
public class Main extends Activity {
private WebView mWebview ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebview = new WebView(this);
mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
final Activity activity = this;
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
});
mWebview .loadUrl("https://www.youtube.com/results?search_query=apples+are+yummy");
setContentView(mWebview);
}
}
,也不要忘了通过
and also don't forget to pass
<uses-permission android:name="android.permission.INTERNET" />
在Android清单文件
in android manifest file
修改
public class WebViewActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://www.youtube.com/results?search_query=apples+are+yummy");
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
VideoView
Uri uri = Uri.parse(URL); //Declare your url here.
VideoView mVideoView = (VideoView)findViewById(R.id.videoview)
mVideoView.setMediaController(new MediaController(this));
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.start();
XML为videoview
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="vertical">
<VideoView android:layout_height="fill_parent"
android:layout_width="fill_parent" android:id="@+id/VideoView"></VideoView>
</LinearLayout>
这篇关于Android的code:我有YouTube网址codeD,但我不能发挥出自己的应用程序内的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文