视频作为启动画面而不是图片 [英] Video as a Splash Screen instead of Picture
问题描述
我在闪屏上做 Android 编程教程,你在其中显示图片或文本 5 秒,而不是进入主应用程序.我的问题是..我想在进入应用程序的下一页之前显示视频文件 5 秒,而不是文本或图片.
I am doing the Android Programming Tutorial on Splash Screens where you show a picture or text for 5 Seconds than it goes to the Main Application. My Question is..Instead of Text or Pictures I want to display a Video File for 5 Seconds before it goes to the Next page of the Application.
我不是在谈论应用程序何时加载我在谈论它何时加载并且您对其进行编程以在单独的 Java & 上显示某些内容XML 页面显示某些内容然后移动到其他内容..这是我当前的代码.
I am not talking about when the Application Loads I am talking about when it is Loaded and you program it to display something on a Separate Java & XML page to display something then move to something else..here is my current code.
@Override
protected void onCreate(Bundle SplashScreen1) {
// TODO Auto-generated method stub
super.onCreate(SplashScreen1);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
ourSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoint = new Intent("com.Player.Splash.STARTINGPOINT");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
那么我该怎么做才能让它显示没有开始/停止等的视频媒体文件.
So What Do I do to make it display a Video Media file without the Start/Stop etc..
推荐答案
1) 创建 SplashScreen.java 类.
1) Create SplashScreen.java class.
2) 在 res 目录中创建一个 raw 文件夹(res/raw).
2) Create a raw folder inside res directory(res/raw).
3) 将您的 mp4 视频文件粘贴到此原始文件夹中(如果您没有任何示例 mp4,可以从以下链接下载).http://www.mediafire.com/download/p05ki89i2dt5x2x/splash.mp4
3) Paste your mp4 video file in this raw folder(if you don't have any sample mp4, you can download from the below link). http://www.mediafire.com/download/p05ki89i2dt5x2x/splash.mp4
4) 然后在 SplashScreen.java 类中添加以下代码.
4) Then add the following code in your SplashScreen.java class.
public class SplashScreenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
VideoView videoHolder = new VideoView(this);
setContentView(videoHolder);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.splash);
videoHolder.setVideoURI(video);
videoHolder.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
jump();
}
});
videoHolder.start();
} catch (Exception ex) {
jump();
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
jump();
return true;
}
private void jump() {
if (isFinishing())
return;
startActivity(new Intent(this, MainActivity.class));
finish();
}
}
注意:splash_activity.xml 不是必需的.
Note: splash_activity.xml is not required.
这篇关于视频作为启动画面而不是图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!