I have been messing around with android for a little over a week now and know a fair amount, yet still lack a ton of knowledge. I am trying to use an mp4 as a splash screen movie activity. And the methods I was told to use all give me a horrible effect. I want a fullscreen horizontal/landscape movie with nothing on the device except the movie...no video controls etc.. I also want the video to be able to be clicked on and destroyed. If you could help I would greatly appreciate any efforts.
问题:
回答1:
I managed to do this and given below is my code for it. First listed is the Activity and later the layout is given.
package com.adnan.demo;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.widget.VideoView;
public class Splash extends Activity implements OnCompletionListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
VideoView video = (VideoView) findViewById(R.id.videoView);
video.setVideoPath("android.resource://com.agileone/raw/" + R.raw.splash);
video.start();
video.setOnCompletionListener(this);
}
@Override
public void onCompletion(MediaPlayer mp)
{
Intent intent = new Intent(this, Home.class);
startActivity(intent);
finish();
}
}
The activity is declared in the manifest file as follows:
<activity android:name=".Splash" android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
As you can see the orientation is set to landscape so the splash screen will always appear in landscape mode. Setting the theme of this activity to @android:style/Theme.NoTitleBar.Fullscreen is important. It makes the video to cover the whole screen. It is important to understand that Android cant scale your video to the displays resolution. So if your videos resolution does not match the device's resolution, you will see black borders to left/right or top/bottom of the video - depending on your videos resolution.
The contents of the layout file splash.xml are given below:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<VideoView android:id="@+id/videoView" android:layout_gravity="center"
android:layout_width="fill_parent" android:layout_height="fill_parent"/>
</FrameLayout>
回答2:
Dont hardcode the package name. Instead you could do this "android.resource://" + getPackageName() + "/"+R.raw.VideoName