First of all, download/save a mp4 file in SD Card of the Android device, eg: "/sdcard/Video/Android in Spaaaaaace!_low.mp4".
<?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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" > <VideoView android:id="@+id/myvideoview" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
package com.AnVideoView; import android.app.Activity; import android.os.Bundle; import android.widget.MediaController; import android.widget.VideoView; public class AnVideoView extends Activity { String SrcPath = "/sdcard/Video/Android in Spaaaaaace!_low.mp4"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview); myVideoView.setVideoPath(SrcPath); myVideoView.setMediaController(new MediaController(this)); myVideoView.requestFocus(); myVideoView.start(); } }
Related Post:
- A simple example using VideoView to play 3gp from YouTube
Updated:
- Using VideoView to play mp4, with MediaController enable/disable
Hi,
ReplyDeleteI m new to android,I used this code I can see Video static (not running,only image from video) and controller pls tell me where I m wrong.
Please let me know your test environment. I test on N1 without problem.
ReplyDeleteI have Problem on emulator-5554..
Deletei shows "This video cannot be Played..
How i set a srcPath.. through Program.
where i keep a Mp4 file..
Reply me ...
Really nice tutorial
ReplyDeletereally nice tutorial, but how to play large video please help me
ReplyDeleteThis is great and it helped for what I was putting together.
ReplyDeleteLet's say you are releasing the apk in the market, how do you get the video to the buyer? How does it get onto the SD card?
hi Nuwud,
ReplyDeleteI think Download using DownloadManager is a solution.
I have Problem on emulator-5554..
ReplyDeletei shows "This video cannot be Played..
How i set a srcPath.. through Program.
where i keep a Mp4 file..
Reply me ...
This comment has been removed by the author.
ReplyDeleteI would just like to say thanks, for your instructions worked first time.
ReplyDeletePlease use: Environment.getExternalStorageDirectory().getPath() instead of "/sdcard"
ReplyDeletehi,its working fine
ReplyDeletehow to solve this type of error
ReplyDelete02-21 12:58:34.490:E/MediaPlayer(393): error (1, -2147483648) 02-21 12:58:34.490: E/MediaPlayer(393): Error (1,-2147483648)
PLz....
That means that either a) the format of the mp4 cannot be played. Convert it or b) the path and name is wrong, you missed something. Check what is contained in your variable and match it to the location of your file
DeleteHi guys I need a bit help. I am trying to play streaming videos from www.hittvchannels.com into my app but I get popup message says Can't play this video.
ReplyDeleteHI how to show the player controsl such as "Play","Pause",Current position, progress, stop etc. ?
ReplyDeleteThe MediaController already set in this example, tap on the video to display it. Read the update post Using VideoView to play mp4, with MediaController enable/disable.
Deletethanx ,verry nyc code examle video view
ReplyDelete