Android - play background music that will play across all activities

自闭症网瘾萝莉.ら 提交于 2019-12-25 04:09:01

问题


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.

Android background music service

Play background music in all activities of Android app

Background music for game app that will play to all class

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.

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?


回答1:


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...



来源:https://stackoverflow.com/questions/33032290/android-play-background-music-that-will-play-across-all-activities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!