Alert.startMIDI () and Alert.startAudio)

Hello

I want to make a sound notification to the user, but I have not noticed that two ways to play an audio notification using Alert.startMIDI () and Alert.startAudio (). Both feel that I can't do play something more generic like a reader mp3 or wav.

Is there a way to do it without using a medium or short [] tune?   How should this be done generally?

Thank you

The notificationsdemo shows how the two methods of notifications.  The first is managed by the BlackBerry Smartphone, which alert the user based on the configuration of the profile.  The second alert an application to trigger an alert.  Here's a simplified example of the first method.

Opinions rendered easy

http://supportforums.BlackBerry.com/T5/Java-development/notifications-made-easy/Ta-p/520626

You can use the Player class to play audio while your application is in the background.

Tags: BlackBerry Developers

Similar Questions

  • Add audio to Dialog.alerts

    Good evening

    Can some give me some guidance how to add sound or make the phone vibrates when the dialog.alert is the trigger. Also any reference to create a user to configure alerts that aduble, (use the audio files on the BB)

    Hello

    You can then:

        public void playOnAlert()
        {
            Alert.startAudio(TUNE, Alert.getVolume());
            Alert.startBuzzer(TUNE, Alert.getVolume());
        }
    
        public void vibrateOnAlert()
        {
            Alert.startVibrate(3000);
        }
    
        public void flashLightOnAlert()
        {
            LED.setState(LED.STATE_BLINKING);
            LED.setConfiguration(100, 1000, LED.BRIGHTNESS_100);
        }
    
        public void stopSound()
        {
            Alert.stopAudio();
            Alert.stopBuzzer();
            Alert.stopVibrate();
    
            LED.setState(LED.STATE_OFF);
        }
    

    You can also use player MMAPI for playing a melody on the alert (do not forget to close correct).

  • startAudio works on a simulator, not on the device

    I've got and 8310 and 8100 and none of them will play any audio device.  This works very well in the Simulator. Probably something stupid I do because I'm new to the development of BB, but I am simply not see:

    final class AudioHelper {
        private static final int VOLUME = 100;
        private static final int FAILED = 2;
        private static final int SUCCESS = 1;
    
        private static short[] failedAudio =
        {
            100, 50, 200, 50, 200, 50, 100, 50, 200, 50
        };       
    
        private static short[] successAudio =
        {
            500, 300, 500, 300, 500, 300, 500, 300, 500, 50
        };
    
        public static void Play(int noise) {
            short[] tune = noise == SUCCESS ? successAudio : failedAudio;
            if (Alert.isBuzzerSupported())
                Alert.startBuzzer(tune, VOLUME);
            else if ( Alert.isAudioSupported())
                Alert.startAudio(tune, VOLUME);
        }
    }
    

    Please note that the setVolume method only accepts values in increments of 10.  A value greater than this is ignored.  You must gradually increase the volume to make sure that it is set at a level you can hear.

  • NotificationsManager.triggerImmediateEvent doesn't care profile?

    Hello

    I add notification capabilities to our application.  Because all UI interactions are managed within the application itself, I decided to go with triggerImmediateEvent / cancelImmediateEvent suite in NotificationsManager.

    What surprised me, this are just my difference caused the LED flashes red, but has not invoked noises / vibrations.  Is this expected behavior?

    I know that I can do on my own (Alert.startAudio/startMIDI/startVibrate), but I want to respect the current user profile.  Once again, 4.7 and offers NotificationsManager.isVibrateOnly (), but I need to support some older phones as well.

    I even created a small application based on the Notifications Made Easy knowledge base article.  My version allows to cancel events and change the level of notification. Someone at - it care to take a look and see if I'm doing something wrong there?

    package com.samples.simpleNotification;
    
    import java.util.Hashtable;
    
    import net.rim.device.api.notification.NotificationsConstants;
    import net.rim.device.api.notification.NotificationsManager;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FieldChangeListener;
    import net.rim.device.api.ui.MenuItem;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.Dialog;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.component.ObjectChoiceField;
    import net.rim.device.api.ui.container.MainScreen;
    
    public final class SimpleNotification extends UiApplication
    {
        //The ID for the notification.
        private static final long ID = 0x749cb23a75c60e2dL;  //com.samples.simpleNotification
    
        //The toString value of this object will be displayed in the user's Profile settings.
        private static Object theSource = new Object()
        {
            public String toString()
            {
                return "Simple Notification";
            }
        };
    
        public static void main(String[] args)
        {
            if ( args.length > 0 && args[0].equals("gui") )
            {
                //Display the GUI.
                SimpleNotification theApp = new SimpleNotification();
                theApp.enterEventDispatcher();
            }
            else
            {
                //Register the notification.
    
                //Register the notification.
                NotificationsManager.registerSource(ID, theSource, NotificationsConstants.IMPORTANT);
            }
        }
    
        public SimpleNotification()
        {
            //A hash table with notification levels in String and integer forms
            final Hashtable notificationLevels = new Hashtable();
            notificationLevels.put("CASUAL", new Integer(NotificationsConstants.CASUAL));
            notificationLevels.put("IMPORTANT", new Integer(NotificationsConstants.IMPORTANT));
            notificationLevels.put("SENSITIVE", new Integer(NotificationsConstants.SENSITIVE));
            notificationLevels.put("CRITICAL", new Integer(NotificationsConstants.CRITICAL));
            notificationLevels.put("DEFAULT", new Integer(NotificationsConstants.DEFAULT_LEVEL));
    
            final String[] levels = new String[] { "CASUAL", "IMPORTANT", "SENSITIVE", "CRITICAL", "DEFAULT" };
    
            final ObjectChoiceField levelChoice = new ObjectChoiceField("Choose notification level: ", levels);
            FieldChangeListener levelListener = new FieldChangeListener() {
                public void fieldChanged(Field field, int context) {
                    String currChoice = levels[levelChoice.getSelectedIndex()];
                    int currLevel = ((Integer) notificationLevels.get(currChoice)).intValue();
                    NotificationsManager.deregisterSource(ID);
                    NotificationsManager.registerSource(ID, theSource, currLevel);
                    levelChoice.setDirty(false);
                }
            };
            levelChoice.setChangeListener(levelListener);
    
            //A MenuItem used to fire the event.
            MenuItem fireEvent = new MenuItem("Trigger Event", 10, 10)
            {
                public void run()
                {
                    NotificationsManager.triggerImmediateEvent(ID, 0, null, null);
                }
            };      
    
            MenuItem cancelEvent = new MenuItem("Cancel Event", 11, 11) {
                public void run() {
                    try {
                        NotificationsManager.cancelImmediateEvent(ID, 0, null, null);
                    } catch (Exception e) {
                        Dialog.inform(e.toString() + " trying to cancel event");
                    }
                }
            };
            MainScreen mainScreen = new MainScreen();
            mainScreen.add(levelChoice);
    
            mainScreen.addMenuItem(fireEvent);
            mainScreen.addMenuItem(cancelEvent);
    
            mainScreen.setTitle(new LabelField("Fire an Event From the Menu"));
            pushScreen(mainScreen);
        }
    }
    

    In fact, I found that the 'Top' and 'Medium' profile work on shelf - there is a noise. "Normal" and "Vibrate only" not - I had to manually 'Edit profile' and change the 'Simple Notification' profile so that they work.  It seems that the default values for profiles except 'Loud' and 'Medium' is not well defined...

  • Which is wrong with this reading of the audio files...! ???

    Hi all

    I try to read two different audio files with the following code piece. individually, they play well. When I try to play at the same time which is at the same time, it is give IllegalStateException and does not play any audio file.

    When I play them separately, they play well. My requirement is to play 1 file as background music and another as foreground.

    Audio playback code.

    public class Audio implements Runnable//extends Thread
    {
        private Class clazz;
        private InputStream is;
        public Player player;
        private String audiofile;
        private int fileType;
        private int mode;
        public Audio(String path, int type, int mode)
        {
         audiofile = path;
         fileType = type;
         this.mode = mode;
        }
        public void run()
        {
                       //this sample demonstrates playing an MP3 file that has been
                       //added as a resource to the project
    
                    try
                       {
                          //retrieve the MP3 file
                          clazz = getClass();
                        //create an instance of the player from the InputStream
                          is = clazz.getResourceAsStream(audiofile);
    
                          // 1-- mpeg, 2-- wav audio files
    
                          if(fileType == 1)
                              player = javax.microedition.media.Manager.createPlayer(is, "audio/mpeg");
                          else if(fileType ==2)
                              player = javax.microedition.media.Manager.createPlayer(is, "audio/x-wav");
                          player.setLoopCount(mode);
                          player.realize();
                          player.prefetch();
                          player.start();
    
                        } catch (Exception ex)
                        {
                            UiApplication.getUiApplication().pushScreen(new CloseScreen("Hello"));
                        }
                }
    }
    
    // if call this, commenting section2 it works well
                   //section1
        Audio at = new Audio("/neon1.wav",2, -1);
        Thread at1 = new Thread(at);
        at1.start();
    
    // if call this, commenting section1 it works well
                   //section2
            Audio at3 = new Audio("/neon1.wav",2, -1);
        Thread at2 = new Thread(at3);
        at2.start();
    
    // when i uncomment both section1 and section2 and execute it is not playing giving an exception IllegalStateException.
    

    all aid should be of great use.

    Thank you and best regards,

    PraveenG

    On the storm, it is not possible to play 2 sounds loaded from a file at a time.  If you try this, the first sound stops and the second sound will be played.

    You can, however, load and play a sound (background music) and play other sounds (sound effects) by using Alert.startAudio ().  The first noise not would be cut.  The only problem with this is that the Alert.startAudio sounds are not the best.

  • Make the loop freezes

    Hello.  I spent the last day or two, trying to figure out the best way to run my game loop.  Here's what I have to present based on examples I found. Thing is that the Simulator hangs during something like half a second when he makes a sound.  Does not matter if I use an alert or j2me stuff.  Note that this works on the storm.

    So I wonder if this method is wrong period.  I suppose I could mute for much of the development and use only on the storm but I'm worried that I'm going down the wrong path period.   I'm also surprised that javaloader is still requiring a reboot of the storm when I download, final COD looks like only 45 k.

    import java.util.*;
    
    import javax.microedition.media.*;
    import javax.microedition.media.control.*;
    
    import net.rim.device.api.system.*;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.*;
    
    public class Tester extends UiApplication
    {
        public static void main( String[] args )
        {
            Tester app = new Tester();
    
            app.enterEventDispatcher();
        }
    
        public Tester()
        {
            pushScreen( new TesterScreen() );
        }
    }
    
    class TesterScreen extends FullScreen
    {
        static public final int     TickPerSec  = 30;
        static public final int     TickLength  = 1000 / TickPerSec;
        static public final int     ScrollSpeed = 10;
    
        private int             m_Tick = 0;
        private Timer           m_Timer;
        private TimerTask       m_TickTask;
    
        private long            m_TimeFPS;
        private long            m_TimeNow;
        private int             m_ElapsedFPS;
        private int             m_TickFPS;
        private String          m_TextFPS;
    
        private Bitmap          m_Background;
        private int             m_BackPos;
    
        private int             m_ToneMode = 0;
    
        private Player          m_Player;
        private ToneControl     m_ToneControl;
    
        static final short[]    m_Tones     = { 1400, 15, 1350, 15, 1320, 20, 1300, 20, 1250, 25, 1200, 35 };
        static final byte[]     m_Sequence  = { ToneControl.VERSION, 1,
                                                67, 16,
                                                69, 16,
                                                67,  8,
                                                65,  8,
                                                64, 48,
                                                62,  8,
                                                60,  8,
                                                59, 16,
                                                57, 16,
                                                59, 32,
                                                59, 32 };
    
        public TesterScreen()
        {
            m_Background = Bitmap.getBitmapResource( "img/splash.jpg" );
            m_BackPos    = 0;
    
            add( new BitmapField( m_Background ) );
    
            try
            {
                m_Player = javax.microedition.media.Manager.createPlayer( javax.microedition.media.Manager.TONE_DEVICE_LOCATOR );
                m_Player.realize();
                //m_Player.prefetch();
            }
            catch( Exception e )
            {
            }
    
            m_ToneControl = (ToneControl)m_Player.getControl( "ToneControl" );
            m_ToneControl.setSequence( m_Sequence );
    
            m_TimeFPS = new Date().getTime();
            m_TickFPS = m_Tick;
    
            m_Timer      = new Timer();
            m_TickTask = new TimerTask()
            {
                public void run()
                {
                    tick();
                }
            };
    
            m_Timer.schedule( m_TickTask, TickLength, TickLength );
        }
    
        public void destroy()
        {
            m_Background    = null;
            m_TickTask      = null;
            m_ToneControl   = null;
    
            if ( m_Timer != null )
            {
                m_Timer.cancel();
                m_Timer = null;
            }
    
            if ( m_Player != null )
            {
                m_Player.close();
                m_Player = null;
            }
        }
    
        public void tick()
        {
            if ( (m_Tick++ % (TickPerSec * 3)) == 0 )
            {
                try
                {
                    switch( m_ToneMode )
                    {
                        case 0:
                            break;
    
                        case 1:
                            if ( m_Player.getState() != Player.STARTED )
                                m_Player.start();
                            break;
    
                        case 2:
                            Alert.startAudio( m_Tones, 100 );
                            break;
                    }
                }
                catch( Exception e )
                {
                }
            }   
    
            m_BackPos += ScrollSpeed;
            if ( m_BackPos > m_Background.getHeight() )
               m_BackPos -= m_Background.getHeight();
    
            invalidate();
        }        
    
        public boolean keyChar( char key, int status, int time )
        {
            switch( key )
            {
                case Characters.ESCAPE:
                    close();
                    return true;
            }
    
            return false;
        }
    
        protected boolean touchEvent( TouchEvent message )
        {
            switch( message.getEvent() )
            {
                case TouchEvent.DOWN:
                    if ( ++m_ToneMode == 3 )
                        m_ToneMode = 0;
                    break;
            }
    
            return true;
        }    
    
        protected void paint( Graphics gd )
        {
            m_TimeNow    = new Date().getTime();
            m_ElapsedFPS = (int)(m_TimeNow - m_TimeFPS);
    
            gd.drawBitmap( 0, m_BackPos, Display.getWidth(), Display.getHeight(), m_Background, 0, 0 );
    
            if ( m_ElapsedFPS > 100 )
            {
                m_TextFPS = "FPS: " + (((m_Tick - m_TickFPS) * 1000) / m_ElapsedFPS);
                m_TickFPS = m_Tick;
                m_TimeFPS = m_TimeNow;
    
                //System.out.println( m_TextFPS );
            }
    
            gd.setColor( 0x00FF0000 );
            gd.drawText( m_TextFPS, 0, 0 );
        }
    
        public void onUiEngineAttached( boolean attached )
        {
            if ( attached == false )
                destroy();
        }
    }
    

    Leigh

    One thing having a TimerTask run so often (like you have with 33 milliseconds) and using Timer.schedule () is that late in running PPP executions all subsequent executions. Which means that if something (like audio) failed the system and delay your TimerTask, the animation (or you) will be very smooth, then he will have to "catch up". You can try to move to Timer.scheduleAtFixedRate () and add this at the beginning of your TimerTask.run)

    long currentTimeMillis = System.currentTimeMillis();long scheduledExecutionTime = scheduledExecutionTime();if ( currentTimeMillis - scheduledExecutionTime >= period ) {
    
        return;}
    

    Where in your case would be TickLength. Basically, it is saying that if execution is late enough where a subsequent run might have taken care of him already, then go this iteration because it will get handled by another.

  • Time in playback of audio files

    Hi all

    I need to play the two files audio different one after the other. in detail, file1.mp3 must be suspended for a while and file2.mp3 must be played immediately without delay, and after having finished filling the file1.mp3 should be played.

    My problem is file1.mp3 is the game until file2.mp3 call, after an elapsed time file2.mp3 plays and then file1.mp3 is not continuous to play how can I fix this problem.

    This is my code to read files. am sure they play,

    try{player1.stop();  // it is stopping
    
    player2.start();  // file is playing but with a time lapse. it is a  file of duration 1sec
    
    player1.start();  // not continuing to play}
    

    but with a period of time.

    Thank you and best regards,

    Praveen

    White,

    After calling player1.stop (), call the player1.setMediaTime (- 1).  This resets the player at the beginning.  Some blackberry models and OS automatically resets to the beginning after you call stop but I know with certainty that the 4.7 STORM is not.

    try
    {
      player1.stop();  // it is stopping
      player1.setMediaTime( -1); // Rewind the sound so it will play from the beginning.
      player2.start();  // file is playing but with a time lapse. it is a file of duration 1sec
      player1.start();  // not continuing to play
    }
    

    Looks like we want to achieve the same thing.  Have a play with background music and sound FX.  I can share my experience with you.  It seems that the audio API for blackberry is very buggy.  For action games high (like I am doing now), I noticed that if you have lots of sound effects, the game freezes just.  I even added code to loop through my sounds hash table and make sure that all of them are arrested before playing a new and sometimes it freezes again.

    I really don't want to use the Alert.startAudio () because you cannot make effects sound pacman but looks like it's maybe the only way to go if you made a game where you don't really know when a sound can be played.  If you were a board game, then that's different... you can pretty much control when a sound is played or not.  You know what I mean?  Let me know if you encounter these problems...

  • PlayTone note value for beep

    Hi all

    I used Alert.startAudio () to create a beep. But the volume is much lower. So I wanted to use Manager.playTone (). But I was stuck on the value of the attribute of the note of the playTone method...

    Can someone give me the note value simple beep!

    Sorry everyone... I just read the documentation of the api correctly and found the solution...

  • Why not the preferences of the general calendar for "the day ends at:" only offers the possibility of 'am' and not 'pm '? And alerts for an event from 14:00 activate at the right time, but it's at 02:00.

    The "day starts at:" options correctly offer options of "midnight" through time "am" to "noon". Thus the "day ends at:" should have options starting with "midi" and moments of "pm" to "midnight", but instead, they are all time 'am '.

    And alerts for an event from 14:00 activate at the right time, but it's at 02:00. Maybe it's a consequence of the above.

    ???

  • Alert for missed messages and calls

    My Adroid contained an I'm bored: a little green light that made me know a message is waiting. Now, I have to turn on the iphone to find out. I activated the alert LED flash, but there is not, and it is on the back of the phone, so is not as good. I miss a feature somewhere?

    # This is not a feature of the iPhone

  • iPhone 6s more not to alert when it is locked and off

    When it is locked and off, my iPhone will not alert sound.  It will be if I unlock and screen is on, but will not otherwise.  Calls went through with the sound, but not with the texts.  I have made sure that the do not disturb settings are turned off and that the ringer is enabled and volume is completely upward.  Someone knows how to fix?  It was like that with IOS 9.3.3 and just updated to 9.3.4 and still no change

    Have you ever tried to force reboot the phone by holding down the button sleep and home for 10 seconds, until the Apple logo comes back again? You won't lose data, but it can clear some problems after installing new software.

  • Tried to share reminders with my husband who refused.  I can't him off sharing and everytime I turn on the phone it alerts me.

    Tried to share reminders with my husband who refused.  I can't him off sharing and everytime I turn on the phone it alerts me.  I think my iPhone is a 4S and it is running iOS 9.3.3.

    If you share a list of reminders - click on the button to the right of the name of the list in the left pane - then click on his name - highlight it and press DELETE

  • AutoPage and alerts Ziftr (pricing) are marked as being incompatible with Firefox 36.0.4. What is Mozilla can fix or is it to the developers of the Add-ons?

    AutoPager both Ziftr alerts appear as incompatibility with the latest version of Firefox - 36.0.4.

    Can we do anything to solve this problem? Is - this problem of Mozilla or developers of the add-on? Oris has a compatibility problem with other ad - the, as often is the case?

    Thanks for your help.

    Hi DavidCal, it is the task of the addon developer to keep their compatible extension, so please try to contact them through the channels of support that they provide - they can probably give you more detailed advice and are the only ones who can fix bugs or make necessary adjustments in the addon for new versions of firefox. Thank you...

  • I've updated to Firefox and still get update alerts. Uninstalled, resettled Firefox latest version, always get several alerts update (opening new tabs)

    I have the latest version (26), but I continue to receive alerts for me to update to Firefox. I uninstalled Firefox and reinstalled last week and now I have three or four alerts at the same time, each of them open in a new tab and out me of some tab I was browsing in. I went to the section using Firefox and it says I have the latest version.

    1. install firefox from its site official http://www.mozilla.org/en-US/

    2. If still getting update to request the removal of the software to add or remove programs, control panel-> add or remove a

    3. make sure that antivirus is perfectly up to date.

  • Safari screen claims to make Apple Macintosh system alert, saying: my data was in danger and telling me to call 1-844-316-5 * 5. I'm guessing it's a scam, but it is also a sign of a problem? I have to run some sort of cleaner? Thank you!

    Hello. When you click on a link in Safari, I got a screen that says: "ATTENTION Verizon Online Lic user: your Apple macintosh has been blocked." Apple Macintosh system alert! System was infected due to an unexpected error. "Immediately, certified technicians Mac 1-844-316-5 * 5" etc.  I guess it's a scam and did not call the number. But it does not suggest that I was hacked somehow? Can I launch a kind of cleaner? Thank you!

    < published by host >

    1 n °

    2. only if these messages appear on trusted sites.

    (142425)

Maybe you are looking for

  • Only to music on the iPhone

    Hello Can we please find a way to limit the music available on the iPhone to the music that we have personally downloaded? I know only through iOS10, we have the opportunity to go to downloaded music, but it may not be a default setting or can it be

  • Bad customer service provided by HP

    Compaq 610 I bought my laptop a year ago. I find problems with my laptop. A few times I found my knees overheating problems is. I found that the towers my fan does not work. I called hp and asked them what to do? A week ago. And they provided the sol

  • Unable to connect to my internet

    Impossible to connect to my internet for a reason any it was working earlier, but not not im.

  • How can I transfer Media Player Playlists and settings from one computer to another?

    How to transfer on sides from one computer to another?I use windows media player to work... I'm getting a new computer... I worked hard to rate/organize my music into playlists, etc... How can I transfer this information to my new computer?

  • What is the benefit of moving to windows windows 8.1 8

    I don't like windows 8, but bought an Acer laptop new a with installed months ago. I uninstalled all the aps of windows 8 and used the desktop computer to install my stand-alone programs and everything works fine now. My question is what is the advan