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