コード例 #1
0
ファイル: Playtone.java プロジェクト: dinesh2043/LotteryApp
 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();
    }
  }
コード例 #3
0
  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
ファイル: Recorder.java プロジェクト: davidkeen/tuner
  public void run() {
    while (controller.okToRun) {
      try {
        recordControl.setRecordStream(bos);
        capturePlayer.start();
        recordControl.startRecord();
        Thread.sleep(recordingTime);
        recordControl.stopRecord();
        recordControl.commit();
        bos.flush();

        // Insert the recorded data into the shared buffer.
        buffer.insert(bos.toByteArray());

        // Reset the ByteArrayOutputStream for reuse.
        bos.reset();
      } catch (InterruptedException e) {

        // If Thread was interrupted, we just want to terminate.
        // Close any open Players
        // Do we need to do this if we set the threads to null
        // from TunerMIDlet?
        if (capturePlayer != null) {
          capturePlayer.close();
        }
      } catch (Exception e) {
        controller.showError(e.getMessage(), new FatalForm(controller));
      }
    }
  }
コード例 #5
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();
  }
コード例 #7
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;
 }
コード例 #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
  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);
    }
  }