Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: how to play mp4 video from URL?

I'm trying to play video but having no luck so I'm testing with some bare bones code to see what the problem is. The following doesn't work and I'm not really sure why:

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.videotest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <uses-permission
    android:name="android.permission.INTERNET" />
    <uses-permission
        android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.videotest.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

MainActivity:

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        VideoView vid = (VideoView) findViewById(R.id.videoView1);
        Uri vidUri = Uri.parse("http://somewebsite.com/somevideo.mp4");
        vid.setVideoURI(vidUri);
        vid.setMediaController(new MediaController(this));        
        vid.start();
     }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

activity_main:

<RelativeLayout 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=".MainActivity" >

    <VideoView
        android:id="@+id/videoView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" />
</RelativeLayout>

This is the error I am given when running the code:

02-18 10:12:44.071: E/MediaPlayer(8357): java.io.FileNotFoundException: No content provider: http://somewebsite.com/somevideo.mp4
like image 700
spacitron Avatar asked Feb 18 '14 09:02

spacitron


People also ask

Can Google play MP4 files?

What if you have a Google Drive MP4 video player? Google Drive has a built-in MP4 video player that works on all devices including computer, Android, iPhone, and iPad. All you need to do is to install the Google Drive app on these devices or use the web interface to watch and play MP4 in Google Drive.


2 Answers

Sample code:

@Override
protected void onCreate(Bundle savedInstanceState)
     // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    try {
        setContentView(R.layout.videodisplay);
        String link="http://s1133.photobucket.com/albums/m590/Anniebabycupcakez/?action=view&amp; current=1376992942447_242.mp4";
        VideoView videoView = (VideoView) findViewById(R.id.VideoView);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        Uri video = Uri.parse(link);
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);
        videoView.start();
    } catch (Exception e) {
        // TODO: handle exception
        Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
    }
}
like image 147
Seraphim's Avatar answered Sep 27 '22 19:09

Seraphim's


Your Uri in not genuine. Try this Uri. Check this link http://androidcodeexamples.blogspot.in/2011/08/how-to-play-mp4-video-in-android-using.html

Uri vidUri = Uri.parse("http://s1133.photobucket.com/user/Anniebabycupcakez/media/1489553974996_37622.mp4.html");
like image 38
Jigar Shekh Avatar answered Sep 27 '22 18:09

Jigar Shekh