Setting Player Source force closes app

36 views
Skip to first unread message

Steve Marcus

unread,
May 12, 2013, 9:52:37 AM5/12/13
to alternate-java-bridg...@googlegroups.com
Hi there, 

Just starting to use Java Bridge and it's great so far! But how do you set Player Source?

I have a file called "beachandwaves.mp3" in the assets folder, and ran this in the emulator:

package com.example.test;

import com.xiledsystems.AlternateJavaBridgelib.components.Component;
import com.xiledsystems.AlternateJavaBridgelib.components.HandlesEventDispatching;
import com.xiledsystems.AlternateJavaBridgelib.components.events.EventDispatcher;
import com.xiledsystems.AlternateJavaBridgelib.components.altbridge.Form;
import com.xiledsystems.AlternateJavaBridgelib.components.altbridge.Player;

public class NewForm extends Form implements HandlesEventDispatching {

// Declare global variables here 

Player player1;

protected void $define() {
  // This sets the UI designed in the graphical editor to our Form's UI.
  setContentView(R.layout.newform);  
 
  player1 = new Player(this);
  player1.Source("beachandwaves.mp3");
  player1.Start();
    
        // This method captures the initialization event of this Form, so we can do stuff when the
        // screen first gets initialized.
        EventDispatcher.registerEventForDelegation(this, "ScreenInitialization", "Initialize");

      etc...
    
    }


It force closes the app every time. What am I doing wrong?

Thanks,



Imp Inc

unread,
May 13, 2013, 2:20:00 AM5/13/13
to alternate-java-bridg...@googlegroups.com
Steve,

 This is a difference with the AltBridge. Most resource files go into the res directories.

/res
      /drawable - (For your images, here you can split up images depending on screensize/orientation using drawable-mdpi, drawable-large, drawable-land, etc ).
      /raw - For all sound, and video files.

In fact, see here for the android explanation of how it handles resources.

Ryan

Steve Marcus

unread,
May 13, 2013, 7:42:02 AM5/13/13
to alternate-java-bridg...@googlegroups.com
Good man! Thanks for that.

Ok I will try /raw folder.

Thanks,

S

Steve Marcus

unread,
May 13, 2013, 3:59:26 PM5/13/13
to alternate-java-bridg...@googlegroups.com
Still the same I'm afraid,

mp3 file is now in res/raw folder and this still force closes the app
player1.Source("beachandwaves.mp3");

Do i need to access it using R id's or something? or using getResources().openRawResource(R.raw.beachandwaves)? The only problem with this is that player1.Source only accepts a String?




Brian Cohen

unread,
May 13, 2013, 4:02:58 PM5/13/13
to Java Bridge Discussion
Can you please post your revised code and the logcat output? It will
help with determining the problem

On May 13, 3:59 pm, Steve Marcus <phantomf...@gmail.com> wrote:
> Still the same I'm afraid,
>
> mp3 file is now in res/raw folder and this still force closes the app
> *player1.Source("beachandwaves.mp3");*
> *
> *

Steve Marcus

unread,
May 13, 2013, 4:24:31 PM5/13/13
to alternate-java-bridg...@googlegroups.com
Yes ok here you go - I am using altbridge-2.3.32.beta (from the update site)





package com.example.test;

import com.xiledsystems.AlternateJavaBridgelib.components.Component;
import com.xiledsystems.AlternateJavaBridgelib.components.HandlesEventDispatching;
import com.xiledsystems.AlternateJavaBridgelib.components.events.EventDispatcher;
import com.xiledsystems.AlternateJavaBridgelib.components.altbridge.Form;
import com.xiledsystems.AlternateJavaBridgelib.components.altbridge.Player;

public class NewForm extends Form implements HandlesEventDispatching {

// Declare global variables here 
Player player1;

@Override
public void preUILoad() {
log.txt
playertest.zip

M. Hossein Amerkashi

unread,
May 13, 2013, 4:35:59 PM5/13/13
to Steve Marcus, alternate-java-bridg...@googlegroups.com
You don't need to specify the .mp3

Change from:
player1.Source("beachandwaves.mp3");
to:
player1.Source("beachandwaves");


--
You received this message because you are subscribed to the Google Groups "Java Bridge Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to alternate-java-bridge-libr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Brian Cohen

unread,
May 13, 2013, 4:38:11 PM5/13/13
to Java Bridge Discussion
He is correct, you don't need the mp3 (it is stripped anyway), but
that doesn't solve the force close problem

Brian Cohen

unread,
May 13, 2013, 4:43:56 PM5/13/13
to Java Bridge Discussion
Steve, I am having the same problem you are. I have never tried any
of these classes myself before, so I could be missing something, but
it appears you are doing it correctly. There is a little big of
vaegary (spelling?) in the javadoc for MediaUtil but from what I see
you are doing it correctly.

Tracing through it looks like there might be a problem with the
"prepare()" method being called in library source. Ryan would know
better than I would, but I'll take a look tonight when I get home from
work, if nobody has solved it I'll see if I can take another look.

What I have found is best in these situations (where you get stuck
with something on the bridge and you can't proceed (because it is or
might be a bug, or you need futher help) is to move on to another,
separate part of your app. Usually somebody is able to help in a
reasonable amount of time and you can come back to it.

Good luck

-Brian

M. Hossein Amerkashi

unread,
May 13, 2013, 4:51:12 PM5/13/13
to Brian Cohen, Java Bridge Discussion
Move code below into initialize method -- capture "Initialize" and on initialize do following:

  player1.Source("beachandwaves");
  player1.Start();

Steve Marcus

unread,
May 13, 2013, 5:01:42 PM5/13/13
to alternate-java-bridg...@googlegroups.com, Brian Cohen
Yes confirmed, removing the .mp3 part does not solve the force close.

Also putting it in initialize does not solve the force close

private void screenInitialized() {
    // This method is run when the screen is initialized, and reports a valid width/height. 

player1.Source("beachandwaves");
  player1.Start();
    }

Imp Inc

unread,
May 13, 2013, 5:16:16 PM5/13/13
to alternate-java-bridg...@googlegroups.com, Brian Cohen
That's not cool! I'll look into it further when I have the time soon.

Ryan

Steve Marcus

unread,
May 14, 2013, 8:03:11 AM5/14/13
to alternate-java-bridg...@googlegroups.com
Update fixed it! Awesome thanks for the prompt replies.

Steve Marcus

unread,
May 14, 2013, 11:12:42 AM5/14/13
to alternate-java-bridg...@googlegroups.com
Sorry another one (related). I am now trying to set the player source to a file on the sdcard - 

String sd = Environment.getExternalStorageDirectory().getAbsolutePath();
player1.Source(sd+"/data/beachandwaves.mp3");
player1.Start();

The file is there and the path appears correctly, but the problem is it strips out the .mp3 part from the filename and so it throws the error

05-14 14:42:33.715: E/Form(1683): Form Screen1 ErrorOccurred, errorNumber = 702, componentType = Player, functionName = Source, messages = Unable to prepare /mnt/sdcard/data/beachandwaves.

Is that something I am doing wrong?


Imp Inc

unread,
May 15, 2013, 10:38:06 AM5/15/13
to alternate-java-bridg...@googlegroups.com
No, it's not you. Obviously, when I made these changes, I didn't spend enough time on them. I'll get it fixed as soon as I can.

Ryan
Message has been deleted

Imp Inc

unread,
May 15, 2013, 1:14:31 PM5/15/13
to alternate-java-bridg...@googlegroups.com
Ok, I put a newer jar file up on the server, so try the Update AltBridge jar file again. I moved the check for file extension to the MediaUtil, rather than stripping the file extenstion immediately after inputting the source. (Now the source String doesn't get modified from what you set it to, whereas before it would strip off the extension).

Ryan

Steve Marcus

unread,
May 16, 2013, 10:06:09 AM5/16/13
to alternate-java-bridg...@googlegroups.com
Awesome thanks. You work at the speed of light!

Imp Inc

unread,
May 16, 2013, 12:44:34 PM5/16/13
to alternate-java-bridg...@googlegroups.com
Heh, thankfully this was a pretty quick and easy fix. I understand everything MUCH better than I did when I made these original changes (which was quite a while ago I must confess, I just never used the Player component).

Thanks for the reports.

I am constantly tweaking and updating things, so there may be a time or two when this kind of thing happens. Most of the time, I'm able to resolve the issue in a reasonable amount of time.

Ryan

Steve Marcus

unread,
Jul 20, 2013, 2:59:14 PM7/20/13
to alternate-java-bridg...@googlegroups.com
Also the Sound component doesn't seem to accept a Source either. It says The method Source() in the type Sound is not applicable for the arguments (String)

Brian Cohen

unread,
Jul 20, 2013, 3:13:46 PM7/20/13
to Steve Marcus, alternate-java-bridg...@googlegroups.com

I apologize ahead of time if this is way wrong. I have not used the sound component before and am not at my computer. But off the top of my head I would say maybe the source is looking for a uri instead of a String?

What parameter type is the source method asking for?

On Jul 20, 2013 2:59 PM, "Steve Marcus" <phant...@gmail.com> wrote:
Also the Sound component doesn't seem to accept a Source either. It says The method Source() in the type Sound is not applicable for the arguments (String)

Steve Marcus

unread,
Jul 20, 2013, 3:29:57 PM7/20/13
to alternate-java-bridg...@googlegroups.com, Steve Marcus
I imagine it should be the same as the Player i.e. sound1.Source("beachandwaves.mp3"); but this does not work and states the above error.

Imp Inc

unread,
Jul 20, 2013, 3:39:03 PM7/20/13
to alternate-java-bridg...@googlegroups.com
Sorry for the duplicate Steve, I believe I originally sent it to just you.

The sound component works a little differently, in that you preload all the sources you want to use with the method addSource(String tag, String fileName). The tag is just a name for you to use later to reference that source. Play(String tag) will play the sound.

Since the Sound component is more designed for short audio files, it makes sense to load them all, and have them ready to play whenever (rather than loading the sound each time you want to play it).

- Ryan

Imp Inc

unread,
Jul 20, 2013, 3:40:33 PM7/20/13
to alternate-java-bridg...@googlegroups.com
Just a brief example:

 sound1.addSource("waves", "beachandwaves.mp3");

 sound1.Play("waves");

- Ryan

Steve Marcus

unread,
Jul 20, 2013, 3:41:30 PM7/20/13
to alternate-java-bridg...@googlegroups.com
Yes that worked! Thanks, thought it might have been something simple..

Thanks for that, I was using it incorrectly.
Reply all
Reply to author
Forward
0 new messages