Exemplo n.º 1
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.º 2
0
  public boolean onTouchEvent(MotionEvent touchevent) {
    switch (touchevent.getAction()) {
      case MotionEvent.ACTION_DOWN:
        {
          x1 = touchevent.getX();
          y1 = touchevent.getY();
          break;
        }
      case MotionEvent.ACTION_UP:
        {
          x2 = touchevent.getX();
          y2 = touchevent.getY();

          // if left to right swipe event on screen
          if (x1 < x2) {
            if (mpCheer.isPlaying()) mpCheer.stop();
            Intent i = new Intent(this, MainActivity.class);
            startActivity(i);
          }

          // if right to left swipe event on screen
          if (x1 > x2) {
            if (mpCheer.isPlaying()) mpCheer.stop();
            Intent i = new Intent(this, Shoes.class);
            startActivity(i);
          }

          break;
        }
    }
    return false;
  }
  /** 画面にタッチされたとき */
  public boolean onTouch(View v, MotionEvent event) {
    if (v == titleView) {
      handler.sendEmptyMessage(1);

      player.stop();
      sePool.play(map.get(R.raw.click), 0.5f, 0.5f, 0, 0, 1.0f);
    } else if (v == endView) {
      handler.sendEmptyMessage(0);

      player.stop();
      sePool.play(map.get(R.raw.click), 0.5f, 0.5f, 0, 0, 1.0f);
    }

    return false;
  }
Exemplo n.º 4
0
  private void playFile() {
    if (playingFile == null || !playingFile.isFile()) resetPlayingFile();
    if (playingFile == null) {
      Toast.makeText(AndroidWave.this, "Cannot play file", Toast.LENGTH_SHORT).show();
      return;
    }
    if (mp != null) mp.stop();
    Log.d("file to play", playingFile.getAbsolutePath());
    mp = MediaPlayer.create(AndroidWave.this, Uri.fromFile(playingFile));
    if (mp == null) {
      Toast.makeText(AndroidWave.this, "Cannot play file", Toast.LENGTH_SHORT).show();
      return;
    }
    mp.setOnCompletionListener(
        new OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer arg0) {
            stopPlayFile();
          }
        });
    sm.stop();
    mp.start();
    playButton.setText(R.string.stop);
    playButton.setBackgroundColor(0xFF009900);
  }
Exemplo n.º 5
0
 public void play(int position) {
   if (mediaPlayer.isPlaying()) {
     mediaPlayer.stop();
   }
   currentPodcastInPlayer = position;
   play();
 }
Exemplo n.º 6
0
        public void onCompletion(MediaPlayer arg0) {
          // TODO Auto-generated method stub
          MmpTool.LOG_DBG("play compeletion!");

          if (mmediaplayer != null) {

            saveProgress(0);
            if (videopl.getShuffleMode(Const.FILTER_VIDEO) == Const.SHUFFLE_ON
                || videopl.getRepeatMode(Const.FILTER_VIDEO) == Const.REPEAT_NONE) {
              if (videopl.getCurrentIndex(Const.FILTER_VIDEO)
                  >= ((videopl.getFileNum(Const.FILTER_VIDEO) - 1))) {
                try {
                  isEnd = true;
                  mmediaplayer.stop();
                  mPlayStatus = VideoConst.PLAY_STATUS_END;
                  throw new Exception("End of PlayList!!!");
                } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
            }

            try {
              autoNext();
            } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }

            if (mOnPBCompleteListener != null) {
              mOnPBCompleteListener.onComplete(pb);
            }
          }
        }
Exemplo n.º 7
0
 public static void stop(Context context) {
   if (mp != null) {
     mp.stop();
     mp.release();
     mp = null;
   }
 }
Exemplo n.º 8
0
 public static void stopMusic() {
   // TODO Auto-generated method stub
   if (playStatus == 1) {
     mediaPlayer.stop();
     playStatus = 0;
   }
 }
 @Override
 public void dispose() {
   if (mediaPlayer.isPlaying()) {
     mediaPlayer.stop();
   }
   mediaPlayer.release();
 }
Exemplo n.º 10
0
 public void stopSong() {
   mPlayer.stop();
   NotificationManager manager =
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
   manager.cancel(NOTIFICATION_ID);
   System.exit(0);
 }
Exemplo n.º 11
0
 @Override
 public boolean onUnbind(Intent intent) {
   // Stop the Mediaplayer
   mPlayer.stop();
   mPlayer.release();
   return false;
 }
Exemplo n.º 12
0
 @Override
 protected void onStop() {
   super.onStop();
   mediaController.hide();
   mediaPlayer.stop();
   mediaPlayer.release();
 }
Exemplo n.º 13
0
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

          super.onCallStateChanged(state, incomingNumber);
          Log.d("radio", " Got something with the phone : " + state);

          if (state != TelephonyManager.CALL_STATE_IDLE) {

            if (mediaPlayer.isPlaying()) {

              mediaPlayer.stop();
              try {
                mediaPlayer.prepareAsync();
              } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
              wasPlaying = true;
            }
          } else if (wasPlaying) {

            mediaPlayer.start();
            wasPlaying = false;
          }
        }
Exemplo n.º 14
0
  public void Down() {
    width = refCanvas.getWidth();
    height = refCanvas.getHeight();

    m.setRotate(degree);

    refCanvas.drawBitmap(
        Bitmap.createBitmap(panda, 0, 0, panda.getWidth(), panda.getHeight(), m, false),
        x,
        y,
        null);

    y += 20;
    degree += 15;
    if (degree > 360) degree -= 360;
    if (y > height && state == 3) {
      y = 0;
      state = 4;
    }
    if (y > height * 3 / 4 && state == 4) {
      wind.stop();
      wind = new MediaPlayer();
      wind = MediaPlayer.create(cont, R.raw.splash);
      wind.start();
      state = 5;
      long time = System.currentTimeMillis();
      while (System.currentTimeMillis() < time + 1000) ;
    }
  }
Exemplo n.º 15
0
 public void Static() {
   time++;
   if (time == 50) {
     state = 1;
     wind.stop();
   }
 }
Exemplo n.º 16
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;
   }
 }
Exemplo n.º 17
0
  private void stop() {
    mMediaPlayer.stop();
    mMediaPlayer = null;

    // Notificationの解除
    stopForeground(true);
  }
Exemplo n.º 18
0
 public void stop() {
   Log.v(TAG, "stop");
   if (mediaPlayer.isPlaying()) {
     stopMonitor.setIsRunning(false);
     mediaPlayer.stop();
   }
 }
 /**
  * メディアの停止.
  *
  * @param response レスポンス
  */
 public void stopMedia(final Intent response) {
   if (mSetMediaType == MEDIA_TYPE_MUSIC) {
     try {
       mMediaPlayer.stop();
       mMediaStatus = MEDIA_PLAYER_STOP;
       sendOnStatusChangeEvent("stop");
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
         mMediaPlayer.reset();
         putMediaId(null, mBackupMediaId);
       }
     } catch (IllegalStateException e) {
       if (BuildConfig.DEBUG) {
         e.printStackTrace();
       }
     }
     response.putExtra(DConnectMessage.EXTRA_RESULT, DConnectMessage.RESULT_OK);
     sendResponse(response);
   } else if (mSetMediaType == MEDIA_TYPE_VIDEO) {
     mMediaStatus = MEDIA_PLAYER_STOP;
     Intent mIntent = new Intent(VideoConst.SEND_HOSTDP_TO_VIDEOPLAYER);
     mIntent.putExtra(VideoConst.EXTRA_NAME, VideoConst.EXTRA_VALUE_VIDEO_PLAYER_STOP);
     getContext().sendBroadcast(mIntent);
     sendOnStatusChangeEvent("stop");
     response.putExtra(DConnectMessage.EXTRA_RESULT, DConnectMessage.RESULT_OK);
     sendResponse(response);
   }
 }
Exemplo n.º 20
0
 private void releaseMediaPlayer() {
   if (mMediaPlayer != null) {
     if (mMediaPlayer.isPlaying()) mMediaPlayer.stop();
     mMediaPlayer.release();
     mMediaPlayer = null;
   }
 }
Exemplo n.º 21
0
 /** 停止播放 */
 public void stopPlayer() {
   if (mPlayer != null) {
     mPlayer.stop();
     mPlayer.release();
     mPlayer = null;
   }
 }
Exemplo n.º 22
0
 private void releasePlayer() {
   if (mPlayer != null) {
     mPlayer.stop();
     mPlayer.release();
     mPlayer = null;
   }
 }
Exemplo n.º 23
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;
    }
  }
Exemplo n.º 24
0
  public void gotoPrevTrack() {

    Log.i(TAG, "REWIND MUSIC");
    if (mPlayer != null && !mLastSong.isEmpty()) {

      mPlayer.stop();

      mIsPrepared = false;

      // set the mSong to the last song added in the []
      mSong = mLastSong.get(mLastSong.size() - 1);

      // remove the last index from the []
      mLastSong.remove(mLastSong.size() - 1);

      try {
        // rest the player back to an idle state
        mPlayer.reset();

        // reset the datasource to the mSong that was updated
        mPlayer.setDataSource(this, Uri.parse(mSongResource[mSong]));

      } catch (IOException e) {
        e.printStackTrace();
      }

      mPlayer.prepareAsync();

      mPlayWhenPrepared = true;

    } else { // if the player is null or the array is empty

      Toast.makeText(this, "No Previous Track Available", Toast.LENGTH_SHORT).show();
    }
  }
Exemplo n.º 25
0
  public void stop() {
    try {
      if (mp != null) {

        if (mp.isPlaying() || isPaused()) {
          if (DBG) {
            Log.d(LCAT, "audio is playing, stop()");
          }
          setState(STATE_STOPPING);
          mp.stop();
          setState(STATE_STOPPED);
          if (remote) {
            stopProgressTimer();
          }
          try {
            mp.prepare();
          } catch (IOException e) {
            Log.e(LCAT, "Error while preparing audio after stop(). Ignoring.");
          } catch (IllegalStateException e) {
            Log.w(LCAT, "Error while preparing audio after stop(). Ignoring.");
          }
        }

        if (isPaused()) {
          paused = false;
        }
      }
    } catch (Throwable t) {
      Log.e(LCAT, "Error : ", t);
    }
  }
Exemplo n.º 26
0
 private void playMusic(String musicPath) {
   mp = new MediaPlayer();
   try {
     mp.setDataSource(RhoFileApi.openFd(musicPath));
   } catch (IllegalArgumentException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IllegalStateException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   try {
     mp.prepare();
   } catch (IllegalStateException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   mp.start();
   try {
     Thread.sleep(3000);
   } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   mp.stop();
   clearMediaPlayerResources();
 }
Exemplo n.º 27
0
 public void stop() {
   if (mediaPlayer == null) return;
   try {
     mediaPlayer.stop();
   } catch (IllegalStateException e) {
   }
 }
Exemplo n.º 28
0
 /** Stops the playing sounds. */
 public static void stopSounds() {
   if (sMediaPlayer != null) {
     sMediaPlayer.stop();
     releaseSound();
   }
   ReadText.stopTts();
 }
Exemplo n.º 29
0
 @Override
 public void stop() {
   mediaPlayer.stop();
   synchronized (this) {
     isPrepared = false;
   }
 }
Exemplo n.º 30
0
 protected void stopPlaying() {
   if (isPlaying) {
     mPlayer.stop();
     mPlayer.release();
     isPlaying = false;
   }
 }