Android-播放可在所有活动中播放的背景音乐 [英] Android - play background music that will play across all activities
问题描述
我已经研究了好几个小时都没有结果.我正在尝试为我的应用程序实现一个简单的背景音乐,该音乐将在所有活动中播放,并在应用程序最小化时暂停.
I have been researching for hours to no avail. I'm trying to implement a simple background music to my app that will play across all activities and pause whenever the app is minimised.
但是似乎没有什么对我有用.
However nothing seems to be working for me.
我已经尝试阅读并访问了以下内容.
I have tried read and visited the following.
http://www.codeproject.com /Articles/258176/Adding-Background-Music-to-Android-App
还有很多其他东西,但总有一件事情似乎不起作用.
And many many others but there is always one thing that doesn't seem to work.
任何人都可以发送一个3活动应用程序的示例,该应用程序在所有活动中都具有背景音频,并在该应用程序不可见时暂停音乐吗?
Can anyone send an example of a 3 activity app that has background audio through all activities and pauses the music when the app is not visible?
推荐答案
创建一个基本活动,并扩展该基本活动中的所有其他活动,并播放bg音乐或您想要的任何内容
create a base activity and extend all other other activities from base activity and play bg music or whatever you want
public class BaseActivty extends AppCompatActivity{
@Override
protected void onPause() {
super.onPause();
// pause music
}
@Override
protected void onResume() {
super.onResume();
// play music
}
}
public class FirstActivty extends BaseActivty{
// perform other stuff here
}
希望对您有帮助...
hope that will help you...
这篇关于Android-播放可在所有活动中播放的背景音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!