Using a FormService to play Sounds

25 views
Skip to first unread message

Steve Marcus

unread,
Oct 22, 2013, 9:01:57 AM10/22/13
to alternate-java-bridg...@googlegroups.com
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();
}

Imp Inc

unread,
Oct 22, 2013, 11:26:36 PM10/22/13
to alternate-java-bridg...@googlegroups.com
Was a bug. Try the new jar.

Steve Marcus

unread,
Oct 26, 2013, 10:17:29 AM10/26/13
to alternate-java-bridg...@googlegroups.com
Hmm still doesn't appear to work. Here is my eclipse test project if you wanted to test it out.



Reply all
Reply to author
Forward
0 new messages