コード例 #1
0
  private void palyMusic(int resid) {
    try {
      if (player != null && player.isPlaying()) {
        player.stop();
        player.release();
      }
      player = MediaPlayer.create(mContext, resid);
      audioManager = (AudioManager) this.getSystemService(mContext.AUDIO_SERVICE);
      // audioManager.setMode(AudioManager.MODE_IN_CALL);// 把模式调成听筒放音模式

      player.stop();
      player.prepare();
      player.start();
      player.setOnCompletionListener(
          new OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
              // TODO Auto-generated method stub
              player.release();
              player = null;
              HaveCallActivity.this.finish();
            }
          });
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
  public boolean onTouchEvent(MotionEvent touchevent) {
    switch (touchevent.getAction()) {
      case MotionEvent.ACTION_DOWN:
        {
          x1 = touchevent.getX();
          y1 = touchevent.getY();
          break;
        }
      case MotionEvent.ACTION_UP:
        {
          x2 = touchevent.getX();
          y2 = touchevent.getY();

          // if left to right swipe event on screen
          if (x1 < x2) {
            if (mpCheer.isPlaying()) mpCheer.stop();
            Intent i = new Intent(this, MainActivity.class);
            startActivity(i);
          }

          // if right to left swipe event on screen
          if (x1 > x2) {
            if (mpCheer.isPlaying()) mpCheer.stop();
            Intent i = new Intent(this, Shoes.class);
            startActivity(i);
          }

          break;
        }
    }
    return false;
  }
コード例 #3
0
  /** 画面にタッチされたとき */
  public boolean onTouch(View v, MotionEvent event) {
    if (v == titleView) {
      handler.sendEmptyMessage(1);

      player.stop();
      sePool.play(map.get(R.raw.click), 0.5f, 0.5f, 0, 0, 1.0f);
    } else if (v == endView) {
      handler.sendEmptyMessage(0);

      player.stop();
      sePool.play(map.get(R.raw.click), 0.5f, 0.5f, 0, 0, 1.0f);
    }

    return false;
  }
コード例 #4
0
ファイル: AndroidWave.java プロジェクト: tiny2cui/androidwave
  private void playFile() {
    if (playingFile == null || !playingFile.isFile()) resetPlayingFile();
    if (playingFile == null) {
      Toast.makeText(AndroidWave.this, "Cannot play file", Toast.LENGTH_SHORT).show();
      return;
    }
    if (mp != null) mp.stop();
    Log.d("file to play", playingFile.getAbsolutePath());
    mp = MediaPlayer.create(AndroidWave.this, Uri.fromFile(playingFile));
    if (mp == null) {
      Toast.makeText(AndroidWave.this, "Cannot play file", Toast.LENGTH_SHORT).show();
      return;
    }
    mp.setOnCompletionListener(
        new OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer arg0) {
            stopPlayFile();
          }
        });
    sm.stop();
    mp.start();
    playButton.setText(R.string.stop);
    playButton.setBackgroundColor(0xFF009900);
  }
コード例 #5
0
ファイル: ContentService.java プロジェクト: gradjoh/Car-Cast
 public void play(int position) {
   if (mediaPlayer.isPlaying()) {
     mediaPlayer.stop();
   }
   currentPodcastInPlayer = position;
   play();
 }
コード例 #6
0
        public void onCompletion(MediaPlayer arg0) {
          // TODO Auto-generated method stub
          MmpTool.LOG_DBG("play compeletion!");

          if (mmediaplayer != null) {

            saveProgress(0);
            if (videopl.getShuffleMode(Const.FILTER_VIDEO) == Const.SHUFFLE_ON
                || videopl.getRepeatMode(Const.FILTER_VIDEO) == Const.REPEAT_NONE) {
              if (videopl.getCurrentIndex(Const.FILTER_VIDEO)
                  >= ((videopl.getFileNum(Const.FILTER_VIDEO) - 1))) {
                try {
                  isEnd = true;
                  mmediaplayer.stop();
                  mPlayStatus = VideoConst.PLAY_STATUS_END;
                  throw new Exception("End of PlayList!!!");
                } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
            }

            try {
              autoNext();
            } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }

            if (mOnPBCompleteListener != null) {
              mOnPBCompleteListener.onComplete(pb);
            }
          }
        }
コード例 #7
0
ファイル: Music.java プロジェクト: acsuit/PA6
 public static void stop(Context context) {
   if (mp != null) {
     mp.stop();
     mp.release();
     mp = null;
   }
 }
コード例 #8
0
 public static void stopMusic() {
   // TODO Auto-generated method stub
   if (playStatus == 1) {
     mediaPlayer.stop();
     playStatus = 0;
   }
 }
コード例 #9
0
 @Override
 public void dispose() {
   if (mediaPlayer.isPlaying()) {
     mediaPlayer.stop();
   }
   mediaPlayer.release();
 }
コード例 #10
0
 public void stopSong() {
   mPlayer.stop();
   NotificationManager manager =
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
   manager.cancel(NOTIFICATION_ID);
   System.exit(0);
 }
コード例 #11
0
 @Override
 public boolean onUnbind(Intent intent) {
   // Stop the Mediaplayer
   mPlayer.stop();
   mPlayer.release();
   return false;
 }
コード例 #12
0
 @Override
 protected void onStop() {
   super.onStop();
   mediaController.hide();
   mediaPlayer.stop();
   mediaPlayer.release();
 }
コード例 #13
0
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

          super.onCallStateChanged(state, incomingNumber);
          Log.d("radio", " Got something with the phone : " + state);

          if (state != TelephonyManager.CALL_STATE_IDLE) {

            if (mediaPlayer.isPlaying()) {

              mediaPlayer.stop();
              try {
                mediaPlayer.prepareAsync();
              } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
              wasPlaying = true;
            }
          } else if (wasPlaying) {

            mediaPlayer.start();
            wasPlaying = false;
          }
        }
コード例 #14
0
  public void Down() {
    width = refCanvas.getWidth();
    height = refCanvas.getHeight();

    m.setRotate(degree);

    refCanvas.drawBitmap(
        Bitmap.createBitmap(panda, 0, 0, panda.getWidth(), panda.getHeight(), m, false),
        x,
        y,
        null);

    y += 20;
    degree += 15;
    if (degree > 360) degree -= 360;
    if (y > height && state == 3) {
      y = 0;
      state = 4;
    }
    if (y > height * 3 / 4 && state == 4) {
      wind.stop();
      wind = new MediaPlayer();
      wind = MediaPlayer.create(cont, R.raw.splash);
      wind.start();
      state = 5;
      long time = System.currentTimeMillis();
      while (System.currentTimeMillis() < time + 1000) ;
    }
  }
コード例 #15
0
 public void Static() {
   time++;
   if (time == 50) {
     state = 1;
     wind.stop();
   }
 }
コード例 #16
0
 /** Stops the currently playing music, and releases resources. */
 private void unload_Music() {
   if (Music != null) {
     if (Music.isPlaying()) Music.stop();
     Music.release();
     Music = null;
   }
 }
コード例 #17
0
  private void stop() {
    mMediaPlayer.stop();
    mMediaPlayer = null;

    // Notificationの解除
    stopForeground(true);
  }
コード例 #18
0
 public void stop() {
   Log.v(TAG, "stop");
   if (mediaPlayer.isPlaying()) {
     stopMonitor.setIsRunning(false);
     mediaPlayer.stop();
   }
 }
コード例 #19
0
 /**
  * メディアの停止.
  *
  * @param response レスポンス
  */
 public void stopMedia(final Intent response) {
   if (mSetMediaType == MEDIA_TYPE_MUSIC) {
     try {
       mMediaPlayer.stop();
       mMediaStatus = MEDIA_PLAYER_STOP;
       sendOnStatusChangeEvent("stop");
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
         mMediaPlayer.reset();
         putMediaId(null, mBackupMediaId);
       }
     } catch (IllegalStateException e) {
       if (BuildConfig.DEBUG) {
         e.printStackTrace();
       }
     }
     response.putExtra(DConnectMessage.EXTRA_RESULT, DConnectMessage.RESULT_OK);
     sendResponse(response);
   } else if (mSetMediaType == MEDIA_TYPE_VIDEO) {
     mMediaStatus = MEDIA_PLAYER_STOP;
     Intent mIntent = new Intent(VideoConst.SEND_HOSTDP_TO_VIDEOPLAYER);
     mIntent.putExtra(VideoConst.EXTRA_NAME, VideoConst.EXTRA_VALUE_VIDEO_PLAYER_STOP);
     getContext().sendBroadcast(mIntent);
     sendOnStatusChangeEvent("stop");
     response.putExtra(DConnectMessage.EXTRA_RESULT, DConnectMessage.RESULT_OK);
     sendResponse(response);
   }
 }
コード例 #20
0
 private void releaseMediaPlayer() {
   if (mMediaPlayer != null) {
     if (mMediaPlayer.isPlaying()) mMediaPlayer.stop();
     mMediaPlayer.release();
     mMediaPlayer = null;
   }
 }
コード例 #21
0
ファイル: MPlayer.java プロジェクト: gesulong/Android_lib
 /** 停止播放 */
 public void stopPlayer() {
   if (mPlayer != null) {
     mPlayer.stop();
     mPlayer.release();
     mPlayer = null;
   }
 }
コード例 #22
0
ファイル: Player.java プロジェクト: treejames/Children
 private void releasePlayer() {
   if (mPlayer != null) {
     mPlayer.stop();
     mPlayer.release();
     mPlayer = null;
   }
 }
コード例 #23
0
ファイル: QtFeedback.java プロジェクト: KDE/android-qt
  public void setFileState(int state) {
    switch (state) {
      case 0:
        m_mediaPlayer.pause();
        break;

      case 1:
        m_mediaPlayer.stop();
        try {
          m_mediaPlayer.prepare();
        } catch (IllegalStateException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
        m_mediaPlayer.seekTo(0);
        break;

      case 2:
      case 3:
        m_mediaPlayer.start();
        break;

      default:
        break;
    }
  }
コード例 #24
0
  public void gotoPrevTrack() {

    Log.i(TAG, "REWIND MUSIC");
    if (mPlayer != null && !mLastSong.isEmpty()) {

      mPlayer.stop();

      mIsPrepared = false;

      // set the mSong to the last song added in the []
      mSong = mLastSong.get(mLastSong.size() - 1);

      // remove the last index from the []
      mLastSong.remove(mLastSong.size() - 1);

      try {
        // rest the player back to an idle state
        mPlayer.reset();

        // reset the datasource to the mSong that was updated
        mPlayer.setDataSource(this, Uri.parse(mSongResource[mSong]));

      } catch (IOException e) {
        e.printStackTrace();
      }

      mPlayer.prepareAsync();

      mPlayWhenPrepared = true;

    } else { // if the player is null or the array is empty

      Toast.makeText(this, "No Previous Track Available", Toast.LENGTH_SHORT).show();
    }
  }
コード例 #25
0
  public void stop() {
    try {
      if (mp != null) {

        if (mp.isPlaying() || isPaused()) {
          if (DBG) {
            Log.d(LCAT, "audio is playing, stop()");
          }
          setState(STATE_STOPPING);
          mp.stop();
          setState(STATE_STOPPED);
          if (remote) {
            stopProgressTimer();
          }
          try {
            mp.prepare();
          } catch (IOException e) {
            Log.e(LCAT, "Error while preparing audio after stop(). Ignoring.");
          } catch (IllegalStateException e) {
            Log.w(LCAT, "Error while preparing audio after stop(). Ignoring.");
          }
        }

        if (isPaused()) {
          paused = false;
        }
      }
    } catch (Throwable t) {
      Log.e(LCAT, "Error : ", t);
    }
  }
コード例 #26
0
ファイル: CameraObject.java プロジェクト: arissetyawan/rhodes
 private void playMusic(String musicPath) {
   mp = new MediaPlayer();
   try {
     mp.setDataSource(RhoFileApi.openFd(musicPath));
   } catch (IllegalArgumentException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IllegalStateException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   try {
     mp.prepare();
   } catch (IllegalStateException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   mp.start();
   try {
     Thread.sleep(3000);
   } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   mp.stop();
   clearMediaPlayerResources();
 }
コード例 #27
0
ファイル: OutgoingRinger.java プロジェクト: nextgens/RedPhone
 public void stop() {
   if (mediaPlayer == null) return;
   try {
     mediaPlayer.stop();
   } catch (IllegalStateException e) {
   }
 }
コード例 #28
0
ファイル: Sound.java プロジェクト: nidok/Anki-Android
 /** Stops the playing sounds. */
 public static void stopSounds() {
   if (sMediaPlayer != null) {
     sMediaPlayer.stop();
     releaseSound();
   }
   ReadText.stopTts();
 }
コード例 #29
0
ファイル: AndroidMusic.java プロジェクト: efz/NinjaAcademy
 @Override
 public void stop() {
   mediaPlayer.stop();
   synchronized (this) {
     isPrepared = false;
   }
 }
コード例 #30
0
ファイル: AudioHandler.java プロジェクト: rayvahey/phonegap
 protected void stopPlaying() {
   if (isPlaying) {
     mPlayer.stop();
     mPlayer.release();
     isPlaying = false;
   }
 }