如何添加背景音乐在Android应用程序? [英] How to add background music in Android Application?

查看:517
本文介绍了如何添加背景音乐在Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个Android应用程序。(如:KBC - 考恩巴内加Carorpati),其中我想添加背景音乐和声音文件

I am creating an android application (like: KBC - Kaun Banega Carorpati), in which i want to add background music and sound file.

我使用的共享preference用于保存用户的选择他/她是否想播放音乐或没有。

I was used shared preference for saving the user's choice whether he/she want to play music or not.

我添加声音文件不同的事件,它工作正常。

I added sound files for different events and it works fine.

,现在我想添加一些背景音乐,可以播放的整个应用程序(所有活动)以及在一些活动我要暂停的背景音乐。

And now i want to add some background music that can play throughout the application (in all activities) and also in some activities i want to pause the background music.

我怎样才能做到这一点?

How i can achieve this ?

推荐答案

如何使用您用来播放音乐的事件在应用程序的开始播放相同的片段?类应用程序是通过它持久的,或者你可以发挥它在后台服务,即使在繁忙的后台线程。

How about using the same snippet you used to play music on events to play at the beginning of the application? A class Application is persistent through it, or you can just play it on a background service, even on a busy background thread.

这篇关于如何添加背景音乐在Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆