/**
   * Plays a tone the specified number of times on the device audio system.
   *
   * @param repeatCount number of times to play tone
   */
  private static void playTone(int repeatCount) throws MediaException, IOException {

    // get tone player
    Player p = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
    p.realize();

    // set tone sequence
    ToneControl tc = (ToneControl) p.getControl("ToneControl");
    tc.setSequence(getToneSequence(repeatCount));

    // crank up the volume
    VolumeControl vc = (VolumeControl) p.getControl("VolumeControl");
    vc.setLevel(BEEP_VOLUME);

    // route audio to speaker phone
    p.prefetch();
    Control[] c = p.getControls();
    for (int i = c.length - 1; i >= 0; --i) {
      if (c[i] instanceof AudioPathControl) {
        AudioPathControl apc = (AudioPathControl) c[i];
        apc.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSFREE);
        break;
      }
    }

    // play
    p.start();
  }
Пример #2
0
 public void run() {
   tempo = 30;
   seq =
       new byte[] {
         ToneControl.VERSION,
         1, // version 1
         ToneControl.TEMPO,
         tempo, // set tempo
         67,
         16, // The
         69,
         16, // hills
         67,
         8, // are
         65,
         8, // a -
         64,
         48, // live
         62,
         8, // with
         60,
         8, // the
         59,
         16, // sound
         57,
         16, // of
         59,
         32, // mu -
         59,
         32 // sic
       };
   try {
     player = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
     player.realize();
     tc = (ToneControl) (player.getControl("ToneControl"));
     tc.setSequence(seq);
     player.start();
   } catch (MediaException pe) {
   } catch (IOException ioe) {
   }
   Player p;
   VolumeControl vc;
   try {
     p = Manager.createPlayer("http://www.youtube.com/watch?v=WEHXP261Q7Y");
     p.realize();
     vc = (VolumeControl) p.getControl("VolumeControl");
     if (vc != null) {
       // vc.setVolume(50);
     }
     p.prefetch();
     p.start();
   } catch (IOException ioe) {
   } catch (MediaException e) {
   }
 }