Ok so I'm trying to put all my sounds onto a FormService.
I have successfully got the Service to bind to the Form using both Events.ServiceBound example and using the Clock example.
But I can't get the sound to play. It keeps saying:
10-22 13:46:31.340: E/Sound(18633): Sound has been tagged to be loaded in onInitialize.
10-22 13:46:31.340: E/Sound(18633): Unable to play. Did you remember to set the Source property? Tag: sound1
The sound is in the raw folder (I also tried putting it in the assets folder) and plays fine if it is in the Form and not the Service.
Any ideas?
My FormService is:
public class SoundService extends FormService implements HandlesEventDispatching {
private Notifier note;
Sound sound1;
protected void $define() {
note = new Notifier(this);
setStickyVal(START_STICKY);
sound1 = new Sound(this);
sound1.addSource("sound1", "snd1.mp3");
EventDispatcher.registerEventForDelegation(this, "startcommand", "onStartCommand");
}
@Override
public boolean dispatchEvent(Component component, String id, String eventName, Object[] args) {
if (component.equals(this) && eventName.equals("onStartCommand")) {
onStart(args[0]);
return true;
}
return false;
}
private void onStart(Object intent1) {
Intent intent = (Intent) intent1;
}
public void ServiceBound() {
note.ShowAlert("Service is now bound to the Form");
//just trying it in different places
sound1.addSource("sound1", "snd1.mp3");
sound1.Play("sound1");
}
And my Form is:
public class NewForm extends Form implements HandlesEventDispatching {
private SoundService myService;
private Button bindBtn;
private boolean bound;
protected void $define() {
setContentView(R.layout.newform);
bindBtn = new Button(this, R.id.aBButton1);
EventDispatcher.registerEventForDelegation(this, "ScreenInitialization", "Initialize");
EventDispatcher.registerEventForDelegation(this, "Click", Events.CLICK);
EventDispatcher.registerEventForDelegation(this, "serviceBindingEvent", Events.SERVICE_BOUND);
}
@Override
public boolean dispatchEvent(Component component, String id, String eventName, Object[] args) {
if (component.equals(this) && eventName.equals("Initialize")) {
screenInitialized();
return true;
}
if (component.equals(bindBtn) && eventName.equals(Events.CLICK)) {
button1();
return true;
}
if (component.equals(this) && eventName.equals(Events.SERVICE_BOUND)) {
serviceBound();
return true;
}
return false;
}
private void button1() {
if (!bound) {
boolean success;
success = BindToService(SoundService.class);
bound = success;
} else {
myService = null;
UnBindService();
bound = false;
}
}
private void serviceBound() {
myService = (SoundService) boundService;
//play sound
myService.ServiceBound();
}