예제 #1
12
  @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;
  }
예제 #2
1
 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;
 }
예제 #3
0
  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);
  }
예제 #4
0
 private void keypadOnDestroy() {
   if (mpDigitBeep != null) {
     mpDigitBeep.release();
     mpErrorBeep.release();
     mpSuccessBeep.release();
     mpDigitBeep = null;
     mpErrorBeep = null;
     mpSuccessBeep = null;
   }
 }
예제 #5
0
 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);
  }
예제 #8
0
 public void onDestroy() {
   if (mp != null) {
     mp.release();
     mp = null;
   }
   // TitaniumMedia clears out the references after onDestroy.
 }
예제 #9
0
 @Override
 protected void onPause() {
   Log.d(TAG, "Pausing...");
   super.onPause();
   gameView.gameLoop.pauseThread();
   gameSong.release();
 }
예제 #10
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;
   }
 }
 @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");
    }
  }
예제 #13
0
 protected void onStop() {
   //	Log.v("detectActivity","stop");
   super.onStop();
   if (mp3 != null) {
     mp3.release();
   }
 }
예제 #14
0
        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;
          }
        };
예제 #15
0
 @Override
 protected void onPause() {
   // TODO Auto-generated method stub
   super.onPause();
   bgSong.release();
   finish();
 }
예제 #16
0
 @Override
 public void onDestroy() {
   if (mediaPlayer != null) {
     mediaPlayer.stop();
     mediaPlayer.release();
   }
 }
예제 #17
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();
    }
  }
 private void resetPlayer() {
   if (mMediaPlayer != null) {
     mMediaPlayer.reset();
     mMediaPlayer.release();
     mMediaPlayer = null;
   }
 }
예제 #19
0
 protected void stopPlaying() {
   if (isPlaying) {
     mPlayer.stop();
     mPlayer.release();
     isPlaying = false;
   }
 }
예제 #20
0
 @Override
 protected void onStop() {
   super.onStop();
   mediaController.hide();
   mediaPlayer.stop();
   mediaPlayer.release();
 }
예제 #21
0
 @Override
 public synchronized void close() {
   if (mediaPlayer != null) {
     mediaPlayer.release();
     mediaPlayer = null;
   }
 }
예제 #22
0
 @Override
 public boolean onUnbind(Intent intent) {
   // Stop the Mediaplayer
   mPlayer.stop();
   mPlayer.release();
   return false;
 }
예제 #23
0
 public void stop() {
   if (mPlayer != null) {
     mPlayer.release();
     mPlayer = null;
     isFirst = true;
   }
 }
예제 #24
0
 private void releaseMediaPlayer() {
   if (mMediaPlayer != null) {
     if (mMediaPlayer.isPlaying()) mMediaPlayer.stop();
     mMediaPlayer.release();
     mMediaPlayer = null;
   }
 }
예제 #25
0
 /** 停止播放 */
 public void stopPlayer() {
   if (mPlayer != null) {
     mPlayer.stop();
     mPlayer.release();
     mPlayer = null;
   }
 }
예제 #26
0
 private void releasePlayer() {
   if (mPlayer != null) {
     mPlayer.stop();
     mPlayer.release();
     mPlayer = null;
   }
 }
예제 #27
0
파일: Music.java 프로젝트: acsuit/PA6
 public static void stop(Context context) {
   if (mp != null) {
     mp.stop();
     mp.release();
     mp = null;
   }
 }
예제 #28
0
 public void release(boolean paramBoolean) {
   if (mediaPlayer != null) {
     mediaPlayer.reset();
     mediaPlayer.release();
     mediaPlayer = null;
   }
 }
예제 #29
0
  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;
    }
  }
예제 #30
0
  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();
  }