I need to use video as my background. First I placed the video file in drawable folder and called as background of LinearLayout
in main.xml. But while running the app, I saw only a black screen. Then I tried to use VideoView
and called it like following:
<VideoView
android:id="@+id/video"
android:layout_width="320px"
android:layout_height="240px"
android:layout_gravity="center"
android:background="@raw/hp"/>
In my activity file I called it with following code snippet:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView video=(VideoView) findViewById(R.id.video);
video.start();
}
But still I am not getting the video file there. My main propose is to use a bubble video as background and putting two bubble buttons on it and gives the user a feel like water view screen. Can anyone help me?
Also the video file I want to use from the res folder. Not from SD card or any outer media folder.
Use IntroVideoSurfaceView on your xml and put your video in
raw/intro.mp4
Full version of the modified version of luigi23 with avoiding some crashes.
nothing on the main activity. you might want to make it fullscreen by adding
Create a file IntroVideoSurfaceView.java
add a "slideshow.mp4" in resources/raw
modify the activity_main.xml with
Some notes.
Adding a video will make your apk huge so you might want to avoid this... From time to time unknown crashes occur even on high end phones (galaxy s6) It's essential to keep the file small.
I have used this code for play video on surface view
xml file
Well my friend, first of all you can't set a background to your
VideoView
and make it play in the background of your screen.Please follow my steps and add your effort and you should be there.
Remove your video from drawable folder and add it to raw folder. Please google how to create a raw folder. It is simple though. And put your video file inside it.
First of all, create a
SurfaceView
in your xml like this.Now, create a class like the one below which can implement
SurfaceView
,Now your class will ask for unimplemented methods to be added. Add those methods by just clicking on "Add unimplemented methods"
Now you will be able to see a auto generated method like this,
And inside this method,add the below code,
I have used
instead of
And used code bellow to setup media player.
I was able to get this working with a combination of the above and the following other two posts:
Android player raising exception prepare failed:status 0x1
How to attach MediaPlayer with SurfaceView in android?