Preferred way to add background music to Android game?

江枫思渺然 提交于 2019-12-06 12:27:27

问题


I want to add background music to my Android game, this needs to be pause able, resume able, etc.

I have found this example: http://www.codeproject.com/Articles/258176/Adding-Background-Music-to-Android-App

However the line

mServ = ((MusicService.ServiceBinderbinder).getService();

Seems to kick up really weird errors, I have no idea what this is trying to do..

If anyone can see how to get this way working or if there is another, better way of doing this?


回答1:


Try this

mServ = ((MusicService.ServiceBinder)binder).getService();

Its working for me. Also Change getService() method in MusicService class as public method.




回答2:


After extensive looking, I have found this other question: Playing BG Music Across Activities in Android

Which points to this code: http://www.rbgrn.net/content/307-light-racer-20-days-61-64-completion

Which seems to work fine. Not sure if this is the best way..




回答3:


Try to use

mServ = ((MusicService.ServiceBinder) binder).getService();

with making getService() public

public class ServiceBinder extends Binder {
    public MusicService getService() {
        return MusicService.this;
    }
}



回答4:


mServ = ((MusicService.ServiceBinder)binder).getService();


来源:https://stackoverflow.com/questions/11591447/preferred-way-to-add-background-music-to-android-game

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