@Override public int onStartCommand(Intent intent, int flags, int startId) { if (mPlayer == null) { mPlayer = new MediaPlayer(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mPlayer.setOnPreparedListener(this); mPlayer.setOnCompletionListener(this); mPlayer.setOnSeekCompleteListener(this); try { mSong = pickNextSong(); mPlayer.setDataSource(this, Uri.parse(mSongResource[mSong])); } catch (IOException e) { e.printStackTrace(); mPlayer.release(); mPlayer = null; } } if (mPlayer != null && !mIsPrepared) { mPlayer.prepareAsync(); mPlayWhenPrepared = true; } return START_STICKY; }
protected long getDuration(String file) { long duration = -2; if (!isPlaying & !isStreaming(file)) { try { mPlayer = new MediaPlayer(); mPlayer.setDataSource("/sdcard/" + file); mPlayer.prepare(); duration = mPlayer.getDuration(); mPlayer.release(); } catch (Exception e) { e.printStackTrace(); return (-3); } } else if (isPlaying & !isStreaming(file)) { duration = mPlayer.getDuration(); } else if (isPlaying & isStreaming(file)) { try { duration = mPlayer.getDuration(); } catch (Exception e) { e.printStackTrace(); return (-4); } } else { return -1; } return duration; }
public void setAudio(Uri audio, String name, Map<String, ?> extras) { if (audio == null) { throw new IllegalArgumentException("Audio URI may not be null."); } if (LOCAL_LOGV) { Log.v(TAG, "Changing audio source to " + audio); } if (mAudioPlayer != null) { mAudioPlayer.reset(); mAudioPlayer.release(); mAudioPlayer = null; } // Reset state variables mIsPrepared = false; mStartWhenPrepared = false; mSeekWhenPrepared = 0; mStopWhenPrepared = false; try { mAudioPlayer = new MediaPlayer(); mAudioPlayer.setOnPreparedListener(mPreparedListener); mAudioPlayer.setDataSource(mContext, audio); mAudioPlayer.prepareAsync(); } catch (IOException e) { Log.e(TAG, "Unexpected IOException.", e); mAudioPlayer.release(); mAudioPlayer = null; } initAudioInfoView(name); }
private void keypadOnDestroy() { if (mpDigitBeep != null) { mpDigitBeep.release(); mpErrorBeep.release(); mpSuccessBeep.release(); mpDigitBeep = null; mpErrorBeep = null; mpSuccessBeep = null; } }
private void clearMediaPlayerResources() { // TODO Auto-generated method stub if (mp != null) { mp.release(); mp = null; } }
public void onDestroy() { Toast.makeText(this, "Terminando o Servi�o", Toast.LENGTH_SHORT).show(); if (mMediaPlayer != null) { mMediaPlayer.release(); mMediaPlayer = null; } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.home: { if (mediaPlayer.isPlaying()) { mediaPlayer.stop(); mediaPlayer.release(); } Intent home = new Intent( Mulakshare_LetterPractice_Activity.this, eslate.main.Main_Menu_Activity.class); home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(home); finish(); return true; } case R.id.action_refresh: { fragment.canvas.resetCanvas(); return true; } } return super.onOptionsItemSelected(item); }
public void onDestroy() { if (mp != null) { mp.release(); mp = null; } // TitaniumMedia clears out the references after onDestroy. }
@Override protected void onPause() { Log.d(TAG, "Pausing..."); super.onPause(); gameView.gameLoop.pauseThread(); gameSong.release(); }
/** Stops the currently playing music, and releases resources. */ private void unload_Music() { if (Music != null) { if (Music.isPlaying()) Music.stop(); Music.release(); Music = null; } }
@Override public void dispose() { if (mediaPlayer.isPlaying()) { mediaPlayer.stop(); } mediaPlayer.release(); }
public void turnOnRadio(String station) { if (mp != null) { mp.stop(); mp.release(); } Logger.d("clock", "turnOnRadio"); try { Logger.d(TAG, "try"); mp = new MediaPlayer(); mp.setScreenOnWhilePlaying(true); mp.setAudioStreamType(AudioManager.STREAM_MUSIC); Logger.d(TAG, "Station---------------------" + station); try { mp.setDataSource(station); } catch (Exception e) { Logger.d(TAG, "default radio"); try { mp.setDataSource(Radiostations.stations.get("DLF")); } catch (Exception ex) { Logger.d(TAG, "f**k this"); } } mp.setVolume(0.99f, 0.99f); mp.setOnCompletionListener(this); mp.setOnPreparedListener(this); mp.prepareAsync(); } catch (Exception ee) { Logger.e("Error", "No Stream"); } }
protected void onStop() { // Log.v("detectActivity","stop"); super.onStop(); if (mp3 != null) { mp3.release(); } }
public void handleMessage(Message msg) { switch (msg.what) { case 1: if (hit == 0) { try { if (alarmMusic.isPlaying()) { alarmMusic.stop(); alarmMusic.reset(); alarmMusic.release(); } } catch (Exception e) { alarmMusic = null; } mVibrator.cancel(); // 恢复系统之前的音量 mAudioManager.setStreamVolume( AudioManager.STREAM_MUSIC, current, AudioManager.FLAG_PLAY_SOUND); AlarmActivity.this.finish(); onStartService(); } else { System.out.println("用户已经操作了"); } break; case 0: mAudioManager.setStreamVolume( AudioManager.STREAM_MUSIC, min + 1, AudioManager.FLAG_PLAY_SOUND); min += 1; System.out.println("min=" + min); break; default: break; } };
@Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); bgSong.release(); finish(); }
@Override public void onDestroy() { if (mediaPlayer != null) { mediaPlayer.stop(); mediaPlayer.release(); } }
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(); } }
private void resetPlayer() { if (mMediaPlayer != null) { mMediaPlayer.reset(); mMediaPlayer.release(); mMediaPlayer = null; } }
protected void stopPlaying() { if (isPlaying) { mPlayer.stop(); mPlayer.release(); isPlaying = false; } }
@Override protected void onStop() { super.onStop(); mediaController.hide(); mediaPlayer.stop(); mediaPlayer.release(); }
@Override public synchronized void close() { if (mediaPlayer != null) { mediaPlayer.release(); mediaPlayer = null; } }
@Override public boolean onUnbind(Intent intent) { // Stop the Mediaplayer mPlayer.stop(); mPlayer.release(); return false; }
public void stop() { if (mPlayer != null) { mPlayer.release(); mPlayer = null; isFirst = true; } }
private void releaseMediaPlayer() { if (mMediaPlayer != null) { if (mMediaPlayer.isPlaying()) mMediaPlayer.stop(); mMediaPlayer.release(); mMediaPlayer = null; } }
/** 停止播放 */ public void stopPlayer() { if (mPlayer != null) { mPlayer.stop(); mPlayer.release(); mPlayer = null; } }
private void releasePlayer() { if (mPlayer != null) { mPlayer.stop(); mPlayer.release(); mPlayer = null; } }
public static void stop(Context context) { if (mp != null) { mp.stop(); mp.release(); mp = null; } }
public void release(boolean paramBoolean) { if (mediaPlayer != null) { mediaPlayer.reset(); mediaPlayer.release(); mediaPlayer = null; } }
private void openVideo() { if (mUri == null || mSurfaceHolder == null) { // not ready for playback just yet, will try again later return; } if (mMediaPlayer != null) { mMediaPlayer.reset(); mMediaPlayer.release(); mMediaPlayer = null; } try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setOnPreparedListener(mPreparedListener); mIsPrepared = false; mMediaPlayer.setOnCompletionListener(mCompletionListener); mMediaPlayer.setOnErrorListener(mErrorListener); mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener); mCurrentBufferPercentage = 0; mMediaPlayer.setDataSource(mContext, mUri); mMediaPlayer.setDisplay(mSurfaceHolder); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.setScreenOnWhilePlaying(true); mMediaPlayer.prepareAsync(); attachMediaController(); } catch (IOException ex) { Log.w("VideoView", "Unable to open content: " + mUri, ex); return; } catch (IllegalArgumentException ex) { Log.w("VideoView", "Unable to open content: " + mUri, ex); return; } }
public void payan() { if (MainActivity.sound) { if (mp_motevaset.isPlaying()) { mp_motevaset.stop(); mp_motevaset.reset(); mp_motevaset.release(); mp_motevaset = null; } } // namayesh emtiaz va az sar giri int bestresult = pref.getInt("best_result_motevaset", 0); String bestresult_string = String.valueOf(bestresult); String emtiaz = String.valueOf(count); Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(500); // mire b activitie result va natijeha ra ha mibarad Intent result_intent = new Intent(getApplicationContext(), Result.class); Bundle extras = new Bundle(); extras.putString("emtiaz", emtiaz); extras.putString("best_emtiaz", bestresult_string); extras.putString("level", "motevaset"); result_intent.putExtras(extras); startActivity(result_intent); overridePendingTransition(R.anim.left, R.anim.abc_fade_out); onDestroy(); }