BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 01-15-2011, 04:00 AM   #1 (permalink)
New Member
 
Join Date: Jan 2011
Model: none
PIN: N/A
Carrier: none
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with Streaming Audio?

Please Login to Remove!

Hi,

I have built an app for a project I am involved in using Eclipse and Blackberry JRE 5.0.0. My problem is I don't own a Blackberry and can only test using the simulators. I made the same app for Android and released it and have had over 400 downloads and a 4.5 star rating. So I released the BB app on App World and in 2 days had over 500 downloads but judging from 4 bad reviews I received it was not working properly on some devices. To be honest I don't know if it worked at all on any devices. So I removed it from App world till I can solve my problem.

The app needs to play some music tracks, I have a couple of short ones that I have added to the resources and can play OK. But there are 8 tracks that are much larger and so I need to stream them from a website. I have a slideshow running while the tracks play. Using the simulators with the 8900 & 8520 I get the slideshow but no audio. With the simulators for 9630, 9550 and 9700 I get both audio and slideshow. But judging from the reviews I have my doubts if any devices are playing the audio.

I have been searching for a solution for days. I don't know why this needs to be so difficult either, I have 4 lines of code on the Android and it works fine. This is a trimmed down version of the code just trying to play the audio.
Code:
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VolumeControl;

import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.MainScreen;

public class AudioPlayer extends MainScreen {
    private Player player;
    private VolumeControl volumeControl;
	
	
    public AudioPlayer() {
        super(NO_VERTICAL_SCROLL);

        AudioThread audio = new AudioThread(this, player, volumeControl);
        audio.start();
    }

    public VolumeControl getVolumeControl( Player p ) {
        return (VolumeControl)p.getControl( "VolumeControl" );
    }

    public void stopAudio() {
        if(player != null) {
            try {
                if (volumeControl != null)
                    volumeControl.setLevel(0);
                player.stop();
            } catch (MediaException e) {
            }
        }
    }
    
    public boolean onClose() {
        stopAudio();
        return super.onClose();
    }	    
}

class AudioThread extends Thread {
    AudioPlayer mainscreen;
    Player player;
    VolumeControl volumeControl;
    String url;
	
    AudioThread(AudioPlayer mainscreen, Player player, VolumeControl volumeControl) {
        this.mainscreen = mainscreen;
        this.player = player;
        this.volumeControl = volumeControl;
    }

    public void run() {
        try {
            url = "http://www.onlinepc.com.au/audio/dis.mp3";
            url += ";deviceside=true";
			
            player = javax.microedition.media.Manager.createPlayer( url );
            player.realize();
            
            volumeControl = mainscreen.getVolumeControl(player);

            if (volumeControl != null)
                volumeControl.setLevel(100);
            
            player.prefetch();
            player.start();
            
        } catch (Exception e) {
        }
    }
}
Originally I had the player stuff in the main code but someone said that putting it in a Thread should stop some lockups. Not sure I did that right though.

If anyone can help me get this code working I will be very greatful.
Offline  
Old 01-15-2011, 10:12 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default Re: Help with Streaming Audio?

The connection parameter ";deviceside=true" is not very usefull without the APN information. The APN must be set either in the TCP options on the phone, or specified by you in the connection string. This APN info is carrier-specific.

See these articles:

Livelink - Redirection

Livelink - Redirection
Offline  
Old 01-15-2011, 03:55 PM   #3 (permalink)
New Member
 
Join Date: Jan 2011
Model: none
PIN: N/A
Carrier: none
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: Help with Streaming Audio?

Quote:
Originally Posted by Dougsg38p View Post
The connection parameter ";deviceside=true" is not very usefull without the APN information. The APN must be set either in the TCP options on the phone, or specified by you in the connection string. This APN info is carrier-specific.

See these articles:

Livelink - Redirection

Livelink - Redirection
Thanks for the advice Doug. Someone did tell me that the ";deviceside=true" was carrier specific but when I removed that I got no audio on any simulator.

So from the article you pointed me to I want to try this code:-
Code:
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.findRecordsByCid("WPTCP");
String uid = null;

for(int i=0; i < records.length; i++)
{
    //Search through all service records to find the
    //valid non-Wi-Fi and non-MMS
    //WAP 2.0 Gateway Service Record.
    if (records[i].isValid() && !records[i].isDisabled())
    {

        if (records[i].getUid() != null && records[i].getUid().length() != 0)
        {
            if ((records[i].getUid().toLowerCase().indexOf("wifi") == -1) &&
                (records[i].getUid().toLowerCase().indexOf("mms") == -1))
            {
                    uid = records[i].getUid();
                    break;
            }
        }
    }
}

if (uid != null)
{

    //open a WAP 2 connection
    Connector.open(_url + ";ConnectionUID=" + uid);

    // not sure what to do with the Connection and the Player

}
else
{

    //Consider another transport or alternative action.
}
So if a uid is found and I get a connection to the file, how do I use this in createPlayer()? As you can see I am a novice. Any help you can offer will be greatly appreciated.

I tried this but nothing :(
Code:
FileConnection con = (FileConnection)Connector.open(url + ";ConnectionUID=" + uid, Connector.READ);
InputStream instream = con.openInputStream();
player = javax.microedition.media.Manager.createPlayer(instream, "audio/mpeg");

Last edited by Krisper : 01-15-2011 at 04:01 PM.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads for: Help with Streaming Audio?
Thread Thread Starter Forum Replies Last Post
Help with streaming audio deanf2 General 9000 Series Discussion - Bold 0 06-22-2009 05:15 PM
8330 Streaming Audio Problem after 4.5 Upgrade otaku91 General 8300 Series Discussion - Curve 1 11-06-2008 08:03 PM
Any free audio streaming programs for 8800? JoeJack101 General BlackBerry Discussion 3 10-04-2008 10:22 AM
A2DP/Bluetooth Audio Streaming to Car Stereo? stac Bluetooth Connection 2 07-05-2007 08:35 AM
Why Did RIM Drop the Ball on Video for the Pearl? SanFrancisco General 8100 Series Discussion - Pearl 12 01-19-2007 06:40 PM





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.