コード例 #1
0
ファイル: RutasAudio.java プロジェクト: nioverde/ugrqr
 @Override
 public void onClick(View v) {
   // TODO Auto-generated method stub
   if (v.getId() == R.id.button3) {
     /** ImageButton onClick event handler. Method which start/pause mediaplayer playing */
     if (!cURL.equals("")) {
       try {
         String s = cURL.replace(" ", "");
         mediaPlayer.setDataSource(s);
         mediaPlayer.prepare();
         // you must call this method after setup the
         // datasource in setDataSource method. After calling prepare() the instance
         // of MediaPlayer starts load data from URL to internal buffer.
       } catch (Exception e) {
         e.printStackTrace();
       }
       mediaFileLengthInMilliseconds =
           mediaPlayer.getDuration(); // gets the song length in milliseconds from URL
       if (!mediaPlayer.isPlaying()) {
         mediaPlayer.start();
         // buttonPlayPause.setImageResource(R.drawable.button_pause);
         // play.setText("Pause");
       } else {
         mediaPlayer.pause();
         // buttonPlayPause.setImageResource(R.drawable.button_play);
         // play.setText("Play");
       }
       primarySeekBarProgressUpdater();
     }
   }
 }
コード例 #2
0
  /** Pauses the current movie being played */
  public boolean pause() {
    if (!isPlayableOnTexture()) {
      // DebugLog.LOGD("Cannot pause this video since it is not on texture");
      return false;
    }

    if ((mCurrentState == MEDIA_STATE.NOT_READY) || (mCurrentState == MEDIA_STATE.ERROR)) {
      // DebugLog.LOGD("Cannot pause this video if it is not ready");
      return false;
    }

    boolean result = false;

    mMediaPlayerLock.lock();
    if (mMediaPlayer != null) {
      if (mMediaPlayer.isPlaying()) {
        try {
          mMediaPlayer.pause();
        } catch (Exception e) {
          mMediaPlayerLock.unlock();
          DebugLog.LOGE("Could not pause playback");
        }
        mCurrentState = MEDIA_STATE.PAUSED;
        result = true;
      }
    }
    mMediaPlayerLock.unlock();

    return result;
  }
コード例 #3
0
 /**
  * Stop playing media source. After call play the player will play data source immediately from
  * the beggining
  */
 public void pause() {
   if (mediaPlayer != null && isPrepared) {
     mediaPlayer.pause();
   } else {
     Log.e(Player.class.getSimpleName(), "Couldn't pause");
   }
 }
コード例 #4
0
  public void playSong(final ViewHolder holder, String name) {
    if (isPlaying == false) {
      try {

        String path = name;
        gus.setDataSource(root + "/" + path);
        gus.setOnCompletionListener(
            new MediaPlayer.OnCompletionListener() {

              @Override
              public void onCompletion(MediaPlayer mp) {
                holder.myImageButton.setBackgroundResource(R.drawable.play);
                isPlaying = false;
              }
            });
        gus.prepare();
        gus.start();
        Log.d("is playing", "true");
        isPlaying = true;
        holder.myImageButton.setBackgroundResource(R.drawable.pausebtn);

      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {

      gus.pause();
      gus.reset();
      isPlaying = false;
      holder.myImageButton.setBackgroundResource(R.drawable.play);
    }
  }
コード例 #5
0
ファイル: PlayActivity.java プロジェクト: phongbm/Music
 @Override
 public void onClick(View view) {
   switch (view.getId()) {
     case R.id.imgPlay:
       if (countClickButtonPlay % 2 == 0) {
         if (!mediaPlayer.isPlaying()) {
           seekBar.setMax((int) TimeUnit.MILLISECONDS.toSeconds(mediaPlayer.getDuration()));
           mediaPlayer.start();
           isPlaying = true;
           updateSeekBarThread = new Thread(updateSeekBar);
           updateSeekBarThread.start();
           imgPlay.setImageResource(R.drawable.ic_media_pause);
         }
       } else {
         if (mediaPlayer.isPlaying()) {
           mediaPlayer.pause();
           imgPlay.setImageResource(R.drawable.ic_media_play);
         }
       }
       countClickButtonPlay++;
       break;
     case R.id.imgSpeaker:
       AudioManager audioManager =
           (AudioManager) PlayActivity.this.getSystemService(Context.AUDIO_SERVICE);
       audioManager.adjustStreamVolume(
           AudioManager.STREAM_MUSIC, AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI);
       break;
   }
 }
コード例 #6
0
ファイル: Player.java プロジェクト: treejames/SoMusic
 /** 暂停播放 */
 public void pause() {
   if (playing != Config.PlayState.STATE_PAUSE) {
     mediaPlayer.pause();
     playing = Config.PlayState.STATE_PAUSE;
     context.sendBroadcast(new Intent(Config.Broadcast.MUSIC_CHANGE));
   }
 }
コード例 #7
0
  /** Pauses the music. */
  public static void pause() {
    // Get a Collection of all the media players in the HashMap.
    Collection<MediaPlayer> mps = sPlayers.values();

    // Iterate through the collection...
    for (MediaPlayer p : mps) {
      // If a media player is playing...
      if (p.isPlaying()) {
        // pause it.
        p.pause();
      }
    }

    // previousMusic should always be something valid, so check to make sure
    // that currentMusic is not signalling nil.
    if (sCurrentMusic != -1) {
      // Set the previous music id to be the current music id.
      sPreviousMusic = sCurrentMusic;
    }

    // Set the current music id flag to signal that there is no current
    // music
    // playing
    sCurrentMusic = -1;
  }
コード例 #8
0
ファイル: MediaPlayerService.java プロジェクト: xuatz/XMPv2
  /** already did null checks for mp */
  public void pause() {
    if (mp == null) {
      Log.e(TAG, "mp is null");
    } else {
      wasPlaying = true;
      mp.pause();

      long millis = System.currentTimeMillis() - mStartTime;
      accumulatedPlaytimeForThisTrack += millis;

      if (audioFocus) {
        am.abandonAudioFocus(mOnAudioFocusChangeListener);
        audioFocus = false;
      }

      //            SharedPreferences pref =
      // PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
      //            SharedPreferences.Editor editor = pref.edit();
      //
      //            editor.putString(XMPSQLiteHelper.COLUMN_SESSION_TITLE, sessionTitle);
      //            editor.putInt("trackIndex", trackIndex);
      //            editor.putInt("trackPosition", mp.getCurrentPosition());
      //            editor.commit();
    }
  }
コード例 #9
0
 public static void pause() {
   // TODO Auto-generated method stub
   if (playStatus == 1) {
     mediaPlayer.pause();
     playStatus = 2;
   }
 }
コード例 #10
0
ファイル: ArtistTracksC.java プロジェクト: fhuang26/spotify2
 public static synchronized void set_playing(boolean flag) {
   playing = flag;
   if (mediaPlayer != null) {
     if (playing) mediaPlayer.start();
     else mediaPlayer.pause();
   }
 }
コード例 #11
0
  @Override
  public void onClick(View v) {
    if (v.getId() == R.id.ButtonTestPlayPause) {
      /** ImageButton onClick event handler. Method which start/pause mediaplayer playing */
      try {
        mediaPlayer.setDataSource(
            "http://stream7.cache12.vcdn.vn/fsfsdfdsfdserwrwq3/df399b944be816f5fcf8d0671209dad5/55a0a05d/2015/05/15/6/6/66dd8254b28ea00774d136e251a40a98.mp3"); // setup song from http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3 URL to mediaplayer data source
        mediaPlayer
            .prepare(); // you must call this method after setup the datasource in setDataSource
        // method. After calling prepare() the instance of MediaPlayer starts load
        // data from URL to internal buffer.
      } catch (Exception e) {
        e.printStackTrace();
      }

      mediaFileLengthInMilliseconds =
          mediaPlayer.getDuration(); // gets the song length in milliseconds from URL

      if (!mediaPlayer.isPlaying()) {
        mediaPlayer.start();
        buttonPlayPause.setImageResource(R.drawable.button_pause);
      } else {
        mediaPlayer.pause();
        buttonPlayPause.setImageResource(R.drawable.button_play);
      }

      primarySeekBarProgressUpdater();
    }
  }
コード例 #12
0
  public void play(Context c) {
    if (isFirst) {
      stop();

      mPlayer = MediaPlayer.create(c, R.raw.one_small_step);
      mPlayer.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
              stop();
            }
          });
      mPlayer.start();
      isFirst = false;
      Log.d("ISFIRST", "is false");
      return;
    }
    if (!isFirst) {
      if (isPause) {
        mPlayer.start();
        isPause = false;
        return;
      }
      if (!isPause) {
        mPlayer.pause();
        isPause = true;
        return;
      }
    }
  }
コード例 #13
0
  /**
   * メディアの一時停止.
   *
   * @return セッションID
   */
  public int pauseMedia() {
    if (mSetMediaType == MEDIA_TYPE_MUSIC
        && mMediaStatus != MEDIA_PLAYER_STOP
        && mMediaStatus != MEDIA_PLAYER_SET) {
      try {
        mMediaStatus = MEDIA_PLAYER_PAUSE;
        mMediaPlayer.pause();
      } catch (IllegalStateException e) {
        if (BuildConfig.DEBUG) {
          e.printStackTrace();
        }
      }
      sendOnStatusChangeEvent("pause");
      return mMediaPlayer.getAudioSessionId();

    } else if (mSetMediaType == MEDIA_TYPE_VIDEO) {
      mMediaStatus = MEDIA_PLAYER_PAUSE;
      Intent mIntent = new Intent(VideoConst.SEND_HOSTDP_TO_VIDEOPLAYER);
      mIntent.putExtra(VideoConst.EXTRA_NAME, VideoConst.EXTRA_VALUE_VIDEO_PLAYER_PAUSE);
      getContext().sendBroadcast(mIntent);
      sendOnStatusChangeEvent("pause");
      return 0;
    } else {
      return 0;
    }
  }
コード例 #14
0
 public void pause() {
   if (mPlayer.isPlaying()) {
     mPlayer.pause();
   } else {
     mPlayer.start();
   }
 }
コード例 #15
0
  private boolean play() {
    try {
      if (mediaPlayer == null) {
        mediaPlayer = new MediaPlayer();
        mPlayerWeakRef = new WeakReference<MediaPlayer>(mediaPlayer);

        mediaPlayer.setAudioStreamType(AudioManager.STREAM_SYSTEM);
        mediaPlayer.setOnCompletionListener(this);

        mediaPlayer.setDataSource(FilePathHelper.getWaveTransFile());
        mediaPlayer.prepare();

      } else {
        if (mediaPlayer.isPlaying()) {
          mediaPlayer.pause();
        }
      }

      mediaPlayer.start();
    } catch (Exception e) {
      e.printStackTrace();
      mediaPlayer = null;
    }

    if (mediaPlayer == null) {
      return false;
    }

    mIsCurrPlaying = true;
    return true;
  }
コード例 #16
0
ファイル: Run.java プロジェクト: changorama/Emotodrome2
 @Override
 protected void onPause() {
   super.onPause();
   spawnerToggle = false;
   mp.pause();
   // openGLRenderer.onPause();
 }
コード例 #17
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;
    }
  }
コード例 #18
0
 /** pause */
 public void pause() throws IllegalStateException {
   if (mmediaplayer != null) {
     if (mPlayStatus == VideoConst.PLAY_STATUS_STARTED) {
       try {
         mmediaplayer.pause();
       } catch (IllegalStateException e) {
         e.printStackTrace();
         sendMsg(VideoConst.MSG_INVALID_STATE);
         throw new IllegalStateException(e);
       }
       mPlayStatus = VideoConst.PLAY_STATUS_PAUSED;
       MmpTool.LOG_DBG("pause!");
     } else {
       try {
         mmediaplayer.start();
       } catch (IllegalStateException e) {
         e.printStackTrace();
         sendMsg(VideoConst.MSG_INVALID_STATE);
         throw new IllegalStateException(e);
       }
       mPlayStatus = VideoConst.PLAY_STATUS_STARTED;
       MmpTool.LOG_DBG("play!");
     }
   }
 }
コード例 #19
0
 public void pause() {
   Log.v(TAG, "pause");
   if (mediaPlayer.isPlaying()) {
     stopMonitor.setIsRunning(false);
     mediaPlayer.pause();
   }
 }
コード例 #20
0
 public void pause() {
   if (mMediaPlayer != null && mIsPrepared) {
     if (mMediaPlayer.isPlaying()) {
       mMediaPlayer.pause();
     }
   }
   mStartWhenPrepared = false;
 }
コード例 #21
0
 public void pause() {
   if (isPlayable() && isPlaying()) {
     removeLoopTimer();
     mPlayer.pause();
     setCurrentState(STATE_PAUSED);
   }
   setIntentState(STATE_PAUSED);
 }
コード例 #22
0
  public void userSeekTo(int _time) {

    if (mPlayer != null && mIsPrepared) {

      mPlayer.pause();
      mPlayer.seekTo(_time);
    }
  }
コード例 #23
0
 public void pauseAudio() {
   if ((mAudioPlayer != null) && mIsPrepared) {
     if (mAudioPlayer.isPlaying()) {
       mAudioPlayer.pause();
     }
   }
   mStartWhenPrepared = false;
 }
コード例 #24
0
 public void processPauseRequest() {
   Logger.debug(TAG, ">>>" + "processPauseRequest");
   if (mState == State.Playing) {
     mState = State.Paused;
     mediaPlayer.pause();
     relaxResource(false);
   }
 }
コード例 #25
0
 @Override
 public void onPause() {
   super.onPause();
   // 当游戏恢复时,如果没有播放背景音乐,开始播放背景音乐
   if (player != null && player.isPlaying()) {
     player.pause();
   }
 }
コード例 #26
0
ファイル: Recorder.java プロジェクト: BukT0p/mrapp
  public void pausePlayback() {
    if (mPlayer == null) {
      return;
    }

    mPlayer.pause();
    setState(PLAYING_PAUSED_STATE);
  }
コード例 #27
0
 public void onResume() {
   super.onResume();
   if (isOpen == true) {
     mediaPlayer.pause();
   } else {
     mediaPlayer.start();
   }
 }
コード例 #28
0
 public void pause() {
   if (mActiveMediaPlayer.isPlaying()) {
     mActiveMediaPlayer.pause();
   }
   if (mShowPlayBtn) {
     mPlayBtn.setVisibility(View.VISIBLE);
   }
 }
コード例 #29
0
ファイル: PlayService.java プロジェクト: chmraping/hello
 /** 暂停音乐 */
 private void pause() {
   if (mediaPlayer != null && mediaPlayer.isPlaying()) {
     mediaPlayer.pause();
     isPause = true;
   } else {
     stop();
   }
 }
コード例 #30
0
  public void musicControl(int _action) {

    switch (_action) {
      case REW:
        gotoPrevTrack();

        break;

      case PLAY:
        Log.i(TAG, "PLAY MUSIC");

        if (mPlayer != null && mIsPrepared) {
          showNotification();
          mPlayer.start();
        }

        break;

      case PAUSE:
        Log.i(TAG, "PAUSE MUSIC");

        if (mPlayer.isPlaying()) {
          mPlayer.pause();
          stopForeground(true);
        }
        break;

      case STOP:
        Log.i(TAG, "STOP MUSIC");

        if (mPlayer != null && mPlayer.isPlaying()) {

          stopForeground(true);

          mPlayer.stop();
          mIsPrepared = false;

          mPlayer.reset();
          try {
            mPlayer.setDataSource(this, Uri.parse(mSongResource[mSong]));
          } catch (IOException e) {
            e.printStackTrace();
          }

          mPlayer.prepareAsync();
          mPlayWhenPrepared = false;
        }

        break;

      case FF:
        Log.i(TAG, "FAST FORWARD MUSIC");

        stopAndSetToSong(mSong, true);

        break;
    }
  }