BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 02-11-2010, 04:49 PM   #1 (permalink)
New Member
 
Join Date: Feb 2010
Model: 9000
PIN: N/A
Carrier: AT&T
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Telling my thread what to do

Please Login to Remove!

Hi,

I created an application that creates an object that extends mainscreen.

that object creates an object that extends Thread.

THAT object gets intantiated and i do a .start() on it.

Naturally, that runs the run() function of that class that extends Thread, right?

I have that run() function do all the steps of creating a media player, prefetching and playing.

Now, how do I control that player with the menu buttons or UI buttons?

the object is called playerThread. Why can't I go playerThread.stopPlaying(); inside the run() of my menuItem???

Code:
class myApp extends UiApplication {
    public static void main(String[] args)
    {
        // Create a new instance of the application.
        myApp theApp = new myApp();

        // To make the application enter the event thread and start processing messages, 
        // we invoke the enterEventDispatcher() method.
        theApp.enterEventDispatcher();
    }

    private myApp()
    {
        // Push the main screen instance onto the UI stack for rendering.
        pushScreen(new myAppScreen());
    }    
}

class myAppScreen extends MainScreen
{
    private String murl;
    private String currentUrlToPlay;
    private HttpConnection conn;
    private InputStream is;
    private SharedInputStream readAhead;
    private Player _player;

    myAppScreen() {
        boolean whereAmI = UiApplication.getUiApplication().isEventThread();
        System.out.println("Am I in the event thread?" + whereAmI);

        PlayerThread playerThread = new PlayerThread();
        playerThread.start();
    }
    
    class PlayerThread extends Thread {

        void startPlayer() {
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    Status.show("invoked message.");
                }
            });

            murl = "*mp3streamURL*;deviceside=true;interface=wifi";
                try
                {
                    conn = (HttpConnection) Connector.open(murl, Connector.READ_WRITE);
                }
                catch (Exception e)
                {
                    murl = "*mp3streamURL*;deviceside=true";
                    try {
                        conn = (HttpConnection) Connector.open(murl, Connector.READ_WRITE);
                    }
                    catch (Exception f) {
                    }
                }
                try
                {
                    is = conn.openInputStream();
                    readAhead = SharedInputStream.getSharedInputStream(is);
                    _player = Manager.createPlayer(readAhead, "audio/mpeg");
                    _player.realize();
                    _player.prefetch();
                    _player.start();
                }
                catch (Exception e) {
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    Status.show("failure.");
                }
            });
                }
        }

        void stopPlaying() {
            _player.stop();
        }

        public void run() {
            startPlayer();
        }
    }

    private MenuItem playItem = new MenuItem("Play", 200000, 10) {
    public void run() {
        Status.show("Connecting...");
    }
    };

    private MenuItem pauseItem = new MenuItem("Pause", 200000, 10) {
    public void run() {
        Status.show("Pausing...");
        playerThread.stopPlaying();
    }
    };
Offline  
Old 02-12-2010, 09:15 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Aug 2008
Model: 8520
OS: 5.0.0.509
PIN: N/A
Carrier: TMo
Posts: 176
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

"Intantiated?"
Offline  
Old 02-12-2010, 04:09 PM   #3 (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

Maybe because you haven't specified the scope of the stopPlaying() method?

Try

public void stopPlaying()
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

EZP2010 USB SPI BIOS Programmer Support for Win7 24 25 93 EEPROM 25 FLASH
$16.99
EZP2010 USB SPI BIOS Programmer Support for Win7 24 25 93 EEPROM 25 FLASH pictureSMAKN USB Programmer CH341A Series Burner Chip 24 EEPROM BIOS LCD Writer 25 S...
$13.67
SMAKN USB Programmer CH341A Series Burner Chip 24 EEPROM BIOS LCD Writer 25 S... picture115 X MICROCHIP 24LC64-I/SN IC EEPROM 64KBIT 400KHZ 8SOIC
$46.9
115 X MICROCHIP 24LC64-I/SN IC EEPROM 64KBIT 400KHZ 8SOIC pictureNew CH341A Series Chip 24 EEPROM BIOS Writer 25 SPI Flash USB Programmer OK 01
$4.17
New CH341A Series Chip 24 EEPROM BIOS Writer 25 SPI Flash USB Programmer OK 01 pictureMint Helmholz 700-375-0lc45 EEPROM 8/16 KBYTE
$188.41
Mint Helmholz 700-375-0lc45 EEPROM 8/16 KBYTE picture






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