Ejemplo n.º 1
0
 @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();
     }
   }
 }
  /** 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;
  }
 /**
  * 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");
   }
 }
  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);
    }
  }
Ejemplo n.º 5
0
 @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;
   }
 }
Ejemplo n.º 6
0
 /** 暂停播放 */
 public void pause() {
   if (playing != Config.PlayState.STATE_PAUSE) {
     mediaPlayer.pause();
     playing = Config.PlayState.STATE_PAUSE;
     context.sendBroadcast(new Intent(Config.Broadcast.MUSIC_CHANGE));
   }
 }
Ejemplo n.º 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;
  }
Ejemplo n.º 8
0
  /** 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();
    }
  }
Ejemplo n.º 9
0
 public static void pause() {
   // TODO Auto-generated method stub
   if (playStatus == 1) {
     mediaPlayer.pause();
     playStatus = 2;
   }
 }
Ejemplo n.º 10
0
 public static synchronized void set_playing(boolean flag) {
   playing = flag;
   if (mediaPlayer != null) {
     if (playing) mediaPlayer.start();
     else mediaPlayer.pause();
   }
 }
  @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();
    }
  }
Ejemplo n.º 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;
      }
    }
  }
  /**
   * メディアの一時停止.
   *
   * @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;
    }
  }
Ejemplo n.º 14
0
 public void pause() {
   if (mPlayer.isPlaying()) {
     mPlayer.pause();
   } else {
     mPlayer.start();
   }
 }
Ejemplo n.º 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;
  }
Ejemplo n.º 16
0
 @Override
 protected void onPause() {
   super.onPause();
   spawnerToggle = false;
   mp.pause();
   // openGLRenderer.onPause();
 }
Ejemplo n.º 17
0
  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;
    }
  }
Ejemplo n.º 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!");
     }
   }
 }
Ejemplo n.º 19
0
 public void pause() {
   Log.v(TAG, "pause");
   if (mediaPlayer.isPlaying()) {
     stopMonitor.setIsRunning(false);
     mediaPlayer.pause();
   }
 }
Ejemplo n.º 20
0
 public void pause() {
   if (mMediaPlayer != null && mIsPrepared) {
     if (mMediaPlayer.isPlaying()) {
       mMediaPlayer.pause();
     }
   }
   mStartWhenPrepared = false;
 }
Ejemplo n.º 21
0
 public void pause() {
   if (isPlayable() && isPlaying()) {
     removeLoopTimer();
     mPlayer.pause();
     setCurrentState(STATE_PAUSED);
   }
   setIntentState(STATE_PAUSED);
 }
Ejemplo n.º 22
0
  public void userSeekTo(int _time) {

    if (mPlayer != null && mIsPrepared) {

      mPlayer.pause();
      mPlayer.seekTo(_time);
    }
  }
Ejemplo n.º 23
0
 public void pauseAudio() {
   if ((mAudioPlayer != null) && mIsPrepared) {
     if (mAudioPlayer.isPlaying()) {
       mAudioPlayer.pause();
     }
   }
   mStartWhenPrepared = false;
 }
Ejemplo n.º 24
0
 public void processPauseRequest() {
   Logger.debug(TAG, ">>>" + "processPauseRequest");
   if (mState == State.Playing) {
     mState = State.Paused;
     mediaPlayer.pause();
     relaxResource(false);
   }
 }
Ejemplo n.º 25
0
 @Override
 public void onPause() {
   super.onPause();
   // 当游戏恢复时,如果没有播放背景音乐,开始播放背景音乐
   if (player != null && player.isPlaying()) {
     player.pause();
   }
 }
Ejemplo n.º 26
0
  public void pausePlayback() {
    if (mPlayer == null) {
      return;
    }

    mPlayer.pause();
    setState(PLAYING_PAUSED_STATE);
  }
Ejemplo n.º 27
0
 public void onResume() {
   super.onResume();
   if (isOpen == true) {
     mediaPlayer.pause();
   } else {
     mediaPlayer.start();
   }
 }
 public void pause() {
   if (mActiveMediaPlayer.isPlaying()) {
     mActiveMediaPlayer.pause();
   }
   if (mShowPlayBtn) {
     mPlayBtn.setVisibility(View.VISIBLE);
   }
 }
Ejemplo n.º 29
0
 /** 暂停音乐 */
 private void pause() {
   if (mediaPlayer != null && mediaPlayer.isPlaying()) {
     mediaPlayer.pause();
     isPause = true;
   } else {
     stop();
   }
 }
Ejemplo n.º 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;
    }
  }