1

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?

Will Richardson
  • 7,780
  • 7
  • 42
  • 56

4 Answers4

3

Try this

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

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

i18n
  • 130
  • 5
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..

Community
  • 1
  • 1
Will Richardson
  • 7,780
  • 7
  • 42
  • 56
  • 2
    You should not only put link in your answer. If the links don't work anymore then your answer is useless. – Thomas Vos May 23 '15 at 12:21
  • Your link is not working anymore but here is almost the same solution https://github.com/44maagnum/princetron_android/blob/master/src/princeTron/UserInterface/MusicManager.java – Tomislav Brabec May 23 '18 at 16:07
1

Try to use

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

with making getService() public

public class ServiceBinder extends Binder {
    public MusicService getService() {
        return MusicService.this;
    }
}
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
0
mServ = ((MusicService.ServiceBinder)binder).getService();
Dexter00
  • 49
  • 1
  • 7