示例#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) {
   }
 }
  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();
    }
  }
  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);
                }
              });
    }
  }
示例#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();
  }
示例#6
0
文件: Notify.java 项目: fin-nick/fj
 private boolean play(String file, int volume) {
   createPlayer(file);
   if (null == file) {
     return false;
   }
   try {
     player.realize();
     setVolume(volume);
     player.prefetch();
     player.start();
   } catch (Exception e) {
     closePlayer();
     return false;
   }
   return true;
 }
示例#7
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
 }
  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;
  }
示例#9
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));
      }
    }
  }
示例#10
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);
    }
  }