Reputation: 4530
I want to play following youtube url in android VideoView but it is not streaming video
https://www.youtube.com/watch?v=h-gEwftyPCg
Following is my code
VideoView videoView = (VideoView) getView().findViewById(R.id.dealVideo);
MediaController mc = new MediaController(getContext());
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
videoView.setVideoURI(Uri.parse("https://www.youtube.com/watch?v=h-gEwftyPCg"));
videoView.start();
I want to support non youtube video url as well
Upvotes: 2
Views: 7421
Reputation:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
accept permission
Upvotes: 0
Reputation: 1
After a long search, I found this way of implementation.
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.about_fragment, container, false);
String frameVideo = "<html><body><br><iframe width=\"320\" height=\"200\" src=\"https://www.youtube.com/embed/XDYbEuY8nIc\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
WebView displayYoutubeVideo = (WebView) rootView.findViewById(R.id.videoView);
displayYoutubeVideo.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
WebSettings webSettings = displayYoutubeVideo.getSettings();
webSettings.setJavaScriptEnabled(true);
displayYoutubeVideo.loadData(frameVideo, "text/html", "utf-8");
return rootView;
}
inside the layout.xml:
<WebView android:id="@+id/videoView"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="-45dp"
android:layout_marginLeft="-5dp"/>
This will work well.
Upvotes: 0
Reputation: 2609
You can not play youtube link directly in VideoView.
You need to integrate youtube player.
Check this out how to do that: https://developers.google.com/youtube/android/player/
Upvotes: 5