如何在android的闪屏中播放音频
如何在启动屏幕期间播放音频。如何在android的闪屏中播放音频,android,Android,如何在启动屏幕期间播放音频。 需要指导。您可以使用该类播放音频文件 范例 MediaPlayer player = new MediaPlayer(); player.setDataSource("/sdcard/audiotrack.mp3"); player.prepare(); player.start(); 您可以使用该类播放音频文件 范例 MediaPlayer player = new MediaPlayer(); player.setDataSource("/sdcard/aud
需要指导。您可以使用该类播放音频文件 范例
MediaPlayer player = new MediaPlayer();
player.setDataSource("/sdcard/audiotrack.mp3");
player.prepare();
player.start();
您可以使用该类播放音频文件 范例
MediaPlayer player = new MediaPlayer();
player.setDataSource("/sdcard/audiotrack.mp3");
player.prepare();
player.start();
我的方法是(无需外部声音,因为我将声音文件放在我的资源文件夹中):
在onCreate中:
mp = MediaPlayer.create(getBaseContext(), R.raw.sound); /*Gets your
soundfile from res/raw/sound.ogg */
mp.start(); //Starts your sound
//Continue with your run/thread-code here
请记住将声音设置为.ogg格式;Android完全支持它
以下关于在启动屏幕活动停止时处理声音的重要事项:
当启动屏幕停止时,有两种管理启动屏幕(及其内部声音)的一般方法:
protected void onStop() {
super.onStop();
ur.removeCallbacks(myRunnable); /*If the application is stopped;
remove the callback, so the next time the
application starts it shows the Splash Screen again, and also, so the
thread-code,
don't continue after the application has stopped */
finish();
onDestroy();
}
protected void onStop() {
super.onStop();
if(mp.isPlaying()){ //Must check if it's playing, otherwise it may be a NPE
mp.pause(); //Pauses the sound
ur.removeCallbacks(myRunnable);
}
}
mp = MediaPlayer.create(getBaseContext(), R.raw.sound); /*Gets your
soundfile from res/raw/sound.ogg */
mp.start(); //Starts your sound
//Continue with your run/thread-code here
请记住将声音设置为.ogg格式;Android完全支持它
以下关于在启动屏幕活动停止时处理声音的重要事项:
当启动屏幕停止时,有两种管理启动屏幕(及其内部声音)的一般方法:
protected void onStop() {
super.onStop();
ur.removeCallbacks(myRunnable); /*If the application is stopped;
remove the callback, so the next time the
application starts it shows the Splash Screen again, and also, so the
thread-code,
don't continue after the application has stopped */
finish();
onDestroy();
}
protected void onStop() {
super.onStop();
if(mp.isPlaying()){ //Must check if it's playing, otherwise it may be a NPE
mp.pause(); //Pauses the sound
ur.removeCallbacks(myRunnable);
}
}
我喜欢第一种选择。你可以更具体一点吗。你有一些代码片段吗?再加上你可以做得更具体些。你有一些代码片段吗?需要注意的是,在Android 2.2之前,用户只有有限的内存来保存应用程序。因此,最好将它们存储在外部内存中。如果你有一些小的声音文件,这并不重要,但是如果你有很多的话,那就不重要了。应该注意的是,在Android 2.2之前,用户只有有限的内存来保存应用程序。因此,最好将它们存储在外部内存中。如果你有一些小的声音文件,这并不重要,但如果你有很多,它会。