예제 #1
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) {
   }
 }
  public void run() {
    try {
      player = Manager.createPlayer("capture://audio?encoding=audio/basic");
      player.realize();

      rCtl = (RecordControl) player.getControl("RecordControl");

      Control[] c = player.getControls();
      for (int i = c.length - 1; i >= 0; i--) {
        if (c[i] instanceof AudioPathControl) {
          apc = (AudioPathControl) c[i];

          oldPath = apc.getAudioPath();
          apc.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSFREE);
          path = apc.getAudioPath();

          break;
        }
      }

      rCtl.setRecordStream(strm);
      rCtl.startRecord();

      player.start();
    } catch (Exception e) {
      final String msg = e.toString();
      UiApplication.getUiApplication()
          .invokeAndWait(
              new Runnable() {
                public void run() {
                  Dialog.inform(msg);
                }
              });
    }
  }
  private void showCamera() {

    try {

      releaseResources();
      player = Manager.createPlayer("capture://video");
      player.addPlayerListener(this);
      player.realize();

      videoControl = (VideoControl) player.getControl("VideoControl");
      aVideoCanvas = new VideoCanvas();
      aVideoCanvas.initControls(videoControl, player);

      aVideoCanvas.addCommand(CMD_RECORD);
      aVideoCanvas.addCommand(CMD_EXIT);
      aVideoCanvas.setCommandListener(this);
      parentMidlet.getDisplay().setCurrent(aVideoCanvas);

      player.start();
      contentType = player.getContentType();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #4
0
  private void showCamera() {
    try {
      mPlayer = Manager.createPlayer("capture://video");
      mPlayer.realize();

      mVideoControl = (VideoControl) mPlayer.getControl("VideoControl");

      Canvas canvas = new CameraCanvas(this, mVideoControl);
      canvas.addCommand(mBackCommand);
      canvas.addCommand(mCaptureCommand);
      canvas.setCommandListener(this);
      mDisplay.setCurrent(canvas);

      /*
      Form form = new Form("Camera form");
      Item item = (Item)mVideoControl.initDisplayMode(
          GUIControl.USE_GUI_PRIMITIVE, null);
      form.append(item);
      form.addCommand(mBackCommand);
      form.addCommand(mCaptureCommand);
      form.setCommandListener(this);
      mDisplay.setCurrent(form);
      */

      mPlayer.start();
    } catch (IOException ioe) {
      handleException(ioe);
    } catch (MediaException me) {
      handleException(me);
    }
  }
  /**
   * 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();
  }
 public static Player getPlayerForURL(String url) {
   Player p = null;
   try {
     p = Manager.createPlayer(url);
   } catch (Exception e) {
     (Logger.getInstance()).error(e, "Failed to get player for audio url: " + url);
     if (p != null) p.close();
     return null;
   }
   return p;
 }
 public void run() {
   if (playSnd) {
     try {
       for (int i = 0; i < tone.length(); ) {
         int note = (tone.charAt(i++) - 'A') + 12 * (tone.charAt(i++) - '0');
         int duration = 150;
         Manager.playTone(note, duration, 100);
         Thread.sleep(duration);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
예제 #8
0
 // #endif
 public static void Tiger_Sound_Play() {
   // #if (TIGER=="TRUE")
   String tempName;
   tempName = "/sound/tiger.mid";
   InputStream isSound = Utils.getResourceAsStream(tempName);
   try {
     SoundPlayer = Manager.createPlayer(isSound, "audio/midi");
     isSound = null;
     SoundPlayer.realize();
     SoundPlayer.prefetch();
     SoundPlayer.setLoopCount(1);
     SoundPlayer.start();
   } catch (Exception e) {
     e.printStackTrace();
   }
   // #endif
 }
예제 #9
0
파일: Notify.java 프로젝트: fin-nick/fj
  /* Creates player for file 'source' */
  private void createPlayer(String source) {
    closePlayer();
    try {
      /* What is file extention? */
      String ext = "wav";
      int point = source.lastIndexOf('.');
      if (-1 != point) {
        ext = source.substring(point + 1).toLowerCase();
      }

      InputStream is = getClass().getResourceAsStream(source);
      if (null != is) {
        player = Manager.createPlayer(is, getMimeType(ext));
        player.addPlayerListener(this);
      }
    } catch (Exception e) {
      closePlayer();
    }
  }
  protected void _preparePlayingMedia()
      throws BroadcastServiceException, IOException, MediaException {
    _isPreparing = true;
    _player.clear();

    for (Enumeration e = _selectedServiceComponent.elements(); e.hasMoreElements(); ) {
      ServiceComponent serviceComponent = (ServiceComponent) e.nextElement();
      BroadcastDatagramConnection connection = getBroadcastDatagramConnection(serviceComponent);
      InputStream in = _getInputStream(connection);
      String mimetype = connection.getMimeType();
      Player newPlayer = Manager.createPlayer(in, mimetype);
      _log.debug("new player created: " + newPlayer);

      if (newPlayer != null) {
        newPlayer.realize();
        _player.put(serviceComponent, newPlayer);
      }
      // else throw some Exception... ?
    }
    _isPreparing = false;
  }
예제 #11
0
  /**
   * Creates a new instance of Recorder
   *
   * @param buffer the shared Buffer.
   * @param controller the controlling TunerMIDlet instance.
   */
  public Recorder(Buffer buffer, TunerMIDlet controller) {
    this.buffer = buffer;
    this.controller = controller;

    // Buffer filling time (s) is FFT length / sample rate (* 1000ms).
    recordingTime = 1000 * controller.getSampleLength() / TunerMIDlet.RATE;

    if (capturePlayer == null) {
      try {
        capturePlayer =
            Manager.createPlayer("capture://audio?encoding=pcm&rate=" + TunerMIDlet.RATE);

        capturePlayer.realize();
        recordControl = (RecordControl) capturePlayer.getControl("RecordControl");

        // Create the internal buffer for the recording
        bos = new ByteArrayOutputStream(controller.getSampleLength());
      } catch (Exception e) {
        // No point continuing without a capturePlayer or recordControl so show fatal error.
        controller.showError(e.getMessage(), new FatalForm(controller));
      }
    }
  }
예제 #12
0
파일: Notify.java 프로젝트: fin-nick/fj
  private void playNotification(int notType) {
    final long now = System.currentTimeMillis();
    if (!isCompulsory(playingType) && isCompulsory(notType)) {
      nextPlayTime = 0;
    }
    if (NOTIFY_ALARM == notType) {
      if (!Options.getBoolean(Options.OPTION_ALARM)) return;
      if (now < nextPlayTime) return;
      nextPlayTime = now + 0; // it is changed
      playingType = notType;
      vibrate(1500);
      if (Options.getBoolean(Options.OPTION_SILENT_MODE)) return;
      playNotify(notType, 100);
      return;
    }

    // #sijapp cond.if modules_MAGIC_EYE is "true" #
    // //eye sound
    if (NOTIFY_EYE == notType) { // eye sound
      if (Options.getBoolean(Options.OPTION_SILENT_MODE)) return; // eye sound
      if (Options.getBoolean(Options.OPTION_EYE_NOTIF)) { // eye sound
        if (!_this.play("eye.wav", 60))
          if (!_this.play("eye.amr", 60)) _this.play("eye.mp3", 60); // eye sound
      } // eye sound
    } // eye sound
    // #sijapp cond.end #
    // //eye sound

    int vibraKind = Options.getInt(Options.OPTION_VIBRATOR);
    if (vibraKind == 2) {
      vibraKind = Jimm.isLocked() ? 1 : 0;
    }
    if ((vibraKind > 0) && ((NOTIFY_MESSAGE == notType) || (NOTIFY_MULTIMESSAGE == notType))) {
      vibrate(Util.strToIntDef(Options.getString(Options.OPTION_VIBRATOR_TIME), 150)); // vibra time
    }

    if (Options.getBoolean(Options.OPTION_SILENT_MODE)) return;
    if (now < nextPlayTime) return;
    nextPlayTime = now + 2000;
    playingType = notType;

    // #sijapp cond.if target is "MIDP2" | target is "MOTOROLA" | target is "SIEMENS2"#
    switch (getNotificationMode(notType)) {
      case 1:
        try {
          switch (notType) {
            case NOTIFY_MESSAGE:
              Manager.playTone(ToneControl.C4, 750, Options.getInt(Options.OPTION_MESS_NOTIF_VOL));
              break;
            case NOTIFY_ONLINE:
            case NOTIFY_OFFLINE: // offline sound
            case NOTIFY_TYPING:
            case NOTIFY_OTHER: // other sound
              Manager.playTone(
                  ToneControl.C4 + 7, 750, Options.getInt(Options.OPTION_ONLINE_NOTIF_VOL));
          }

        } catch (Exception e) {
        }
        break;

      case 2:
        int notifyType = NOTIFY_MESSAGE;
        int volume = 0;
        switch (notType) {
          case NOTIFY_MESSAGE:
            volume = Options.getInt(Options.OPTION_MESS_NOTIF_VOL);
            break;

          case NOTIFY_ONLINE:
            volume = Options.getInt(Options.OPTION_ONLINE_NOTIF_VOL);
            break;

          case NOTIFY_OFFLINE: // offline sound
            volume = Options.getInt(Options.OPTION_OFFLINE_NOTIF_VOL); // offline sound
            break; // offline sound

          case NOTIFY_TYPING:
            volume = Options.getInt(Options.OPTION_TYPING_VOL); // typing
            break;

          case NOTIFY_OTHER: // other sound
            volume = Options.getInt(Options.OPTION_OTHER_NOTIF_VOL); // other sound
            break; // other sound
        }
        playNotify(notType, volume);
        break;
    }
  }
예제 #13
0
  public void start() {
    mRunning = true;
    mSession.setTimestampClock(
        new TimestampClock() {
          public int getCurrentTimestamp() {
            return getCurTs();
          }
        });
    try {
      mPlayer =
          Manager.createPlayer(
              new DataSource(null) {
                SourceStream[] mStream = {mInput};

                public void connect() throws IOException {
                  sLogger.info("connect data source");
                }

                public void disconnect() {
                  sLogger.info("disconnect data source");
                }

                public String getContentType() {
                  return "audio/amr";
                }

                public SourceStream[] getStreams() {
                  return mStream;
                }

                public void start() throws IOException {
                  sLogger.info("start data source");
                }

                public void stop() throws IOException {
                  sLogger.info("start data source");
                }

                public Control getControl(String controlType) {
                  return null;
                }

                public Control[] getControls() {
                  return null;
                }
              });

      mPlayer.addPlayerListener(this);
      mPlayer.realize();
      AudioPathControl lPathCtr =
          (AudioPathControl)
              mPlayer.getControl("net.rim.device.api.media.control.AudioPathControl");
      lPathCtr.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSET);
      mPlayer.prefetch();
      // if ( DeviceInfo.isSimulator() == false) { //only start player on real device
      mPlayer.start();

      if (sLogger.isLevelEnabled(Logger.Info)) sLogger.info("Player is started .");
      // }

    } catch (Throwable e) {
      sLogger.error("player error:", e);
    }
  }