Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play video from url in VideoView [Android]

Tags:

I found a similar questions but nothing work for me. I try play video from this url:

http://videocdn.bodybuilding.com/video/mp4/62000/62792m.mp4 

My java code:

VideoView videoView= (VideoView)findViewById(R.id.exerciseVideo);     Uri uri = Uri.parse(TEST_URL);     videoView.setVideoURI(uri);     videoView.requestFocus();     videoView.start(); 

When I run app nothing is displayed in activity and IDE does not show any errors. ANy idea, please?

EDIT:

My activity where I want to show video:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"         xmlns:tools="http://schemas.android.com/tools"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:paddingBottom="@dimen/activity_vertical_margin"         android:paddingLeft="@dimen/activity_horizontal_margin"         android:paddingRight="@dimen/activity_horizontal_margin"         android:paddingTop="@dimen/activity_vertical_margin"         tools:context="com.example.martin.fitnessapp.ExerciseDetailActivity"         android:orientation="vertical">           <LinearLayout             android:orientation="horizontal"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:weightSum="2">             <ImageView                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/exerciseImgA"                 android:layout_weight="1"                 android:scaleType="fitCenter"                 android:adjustViewBounds="true"                 android:paddingRight="8dp"/>              <ImageView                 android:layout_width="fill_parent"                 android:layout_height="wrap_content"                 android:id="@+id/exerciseImgB"                 android:layout_weight="1"                 android:scaleType="fitCenter"                 android:adjustViewBounds="true"                 android:paddingLeft="8dp"/>         </LinearLayout>          <TextView             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:textAppearance="?android:attr/textAppearanceMedium"             android:text=""             android:id="@+id/exerciseDesc" />          <VideoView             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:id="@+id/exerciseVideo" />          <ImageView             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:id="@+id/guideImg"             android:scaleType="fitCenter"             android:adjustViewBounds="true"/>       </LinearLayout> </ScrollView> 
like image 826
Aligator Avatar asked Nov 04 '16 23:11

Aligator


People also ask

Can I play youtube video in VideoView Android?

Watch the video tutorial how to play Youtube videos in Android with VideoView with Android Studio version 1.5: Download free slideshow app from here and install it on your device to see an youtube video.

How do I play music from URL on Android?

String fileUrl = "http://192.168.1.131/myproject/songs/xyz"; String url = "http://myserver/songs/xyz"; //(myserver -> A remote server) mVideoView. setVideoURI(Uri. parse(fileUrl)); mVideoView. requestFocus();


2 Answers

Try this code.. This code works perfectly for me..

VideoView videoView = findViewById(R.id.videoView); videoView.setVideoPath("http://videocdn.bodybuilding.com/video/mp4/62000/62792m.mp4"); videoView.start(); 
like image 94
Vishnu M Menon Avatar answered Sep 20 '22 21:09

Vishnu M Menon


For me, changing the URL from

"http://videocdn.bodybuilding.com/video/mp4/62000/62792m.mp4" 

to:

"https://videocdn.bodybuilding.com/video/mp4/62000/62792m.mp4" 

made it work.

In other words, I used HTTPS instead of HTTP.

I used the following code to start the video:

final VideoView videoView = findViewById(R.id.videoview); //id in your xml file videoView.setVideoURI(Uri.parse(URL)); //the string of the URL mentioned above videoView.requestFocus(); videoView.start(); 
like image 21
mickmick Avatar answered Sep 21 '22 21:09

mickmick