本文整理匯總了Java中android.media.MediaPlayer.stop方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaPlayer.stop方法的具體用法?Java MediaPlayer.stop怎麽用?Java MediaPlayer.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.stop方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: stop
import android.media.MediaPlayer; //導入方法依賴的package包/類
/**
* stop playing audio
*
* @return
*/
public synchronized UDAudio stop() {
final MediaPlayer player = getMediaPlayer();
if (player != null && player.isPlaying()) {
try {
player.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
return this;
}
示例2: onCompletion
import android.media.MediaPlayer; //導入方法依賴的package包/類
/**
* @param mp
*/
@Override
public void onCompletion(MediaPlayer mp) {
if (mp != null) {
synchronized (mp) {
try {
mp.stop();
mp.reset();
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (mCallback != null) {
LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "onComplete", "OnComplete"));
}
}
示例3: playRecording
import android.media.MediaPlayer; //導入方法依賴的package包/類
public static void playRecording(Context context, MediaPlayer mediaPlayer, String recordingName) {
try {
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.reset(); //Before a setDataSource call, you need to reset MP obj.
mediaPlayer.setDataSource(context.getFilesDir().getAbsolutePath() + "/" + recordingName);
mediaPlayer.prepare();
mediaPlayer.start();
} else {
mediaPlayer.reset(); //Before a setDataSource call, you need to reset MP obj.
mediaPlayer.setDataSource(context.getFilesDir().getAbsolutePath() + "/" + recordingName);
mediaPlayer.prepare();
mediaPlayer.start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: onPlayClick
import android.media.MediaPlayer; //導入方法依賴的package包/類
public void onPlayClick(View v) {
if (!mPlaying) {
try {
mPlayer = new MediaPlayer();
AssetFileDescriptor fd = getResources().openRawResourceFd(R.raw.space);
mPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
mPlayer.setOnCompletionListener(mOnCompletionListener);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.prepare();
mPlayer.start();
mPlaying = true;
setState(STATE_PLAYING);
} catch (IOException e) {
Log.e(TAG, "error trying to play a sound");
}
} else {
mPlayer.setOnCompletionListener(null);
mPlayer.stop();
mPlayer.release();
mPlayer = null;
mPlaying = false;
setState(STATE_IDLE);
}
}
示例5: onPlaybackClick
import android.media.MediaPlayer; //導入方法依賴的package包/類
public void onPlaybackClick(View v) {
File f = new File(getExternalFilesDir(null), "recording.mp4");
if (!mPlaying) {
try {
mPlayer = new MediaPlayer();
mPlayer.setDataSource(f.getAbsolutePath());
mPlayer.setOnCompletionListener(mOnCompletionListener);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.prepare();
mPlayer.start();
mPlaying = true;
setState(STATE_PLAYING_BACK);
} catch (IOException e) {
Log.e(TAG, "error trying to playback recording");
}
} else {
mPlayer.setOnCompletionListener(null);
mPlayer.stop();
mPlayer.release();
mPlayer = null;
mPlaying = false;
setState(STATE_IDLE);
}
}
示例6: onClickCheckBox
import android.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void onClickCheckBox(int p,CheckBox checkBox,TextView title)
{
HashMap<String,String> map = mArrayList.get(p);
if(checkBox.isChecked())
{
title.setPaintFlags(title.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLAG);
MediaPlayer player = MediaPlayer.create(getContext(),R.raw.ding);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
if(player.isPlaying())
player.stop();
else
player.start();
mTodo.updateData(keyName,1,map.get("id"));
mArrayList = mTodo.getData(keyName);
}
else
{
title.setPaintFlags(title.getPaintFlags()&(~Paint.STRIKE_THRU_TEXT_FLAG));
mTodo.updateData(keyName,0,map.get("id"));
mArrayList = mTodo.getData(keyName);
}
}
示例7: startPlayer
import android.media.MediaPlayer; //導入方法依賴的package包/類
private void startPlayer() {
mPlayer = new MediaPlayer();
mPlayer.setOnErrorListener(mErrorListener);
try {
isAlarmRinging = true;
// add vibration to alarm alert if it is set
//if (App.getState().settings().vibrate()) {
mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
mHandler.post(mVibrationRunnable);
//}
// Player setup is here
String ringtone;// = App.getState().settings().ringtone();
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
// && ringtone.startsWith("content://media/external/")
// && checkSelfPermission(
// Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM).toString();
//}
mPlayer.setDataSource(this, Uri.parse(ringtone));
mPlayer.setLooping(true);
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mPlayer.setVolume(mVolumeLevel, mVolumeLevel);
mPlayer.prepare();
mPlayer.start();
//if (App.getState().settings().ramping()) {
// mHandler.postDelayed(mVolumeRunnable, VOLUME_INCREASE_DELAY);
//} else {
mPlayer.setVolume(MAX_VOLUME, MAX_VOLUME);
//}
} catch (Exception e) {
isAlarmRinging = false;
if (mPlayer.isPlaying()) {
mPlayer.stop();
}
stopSelf();
}
}
示例8: stopMedia
import android.media.MediaPlayer; //導入方法依賴的package包/類
/**
* 使用完MediaPlayer需要回收資源。MediaPlayer是很消耗係統資源的,所以在使用完MediaPlayer,不要等待係統自動回收,最好是主動回收資源。
*/
private void stopMedia(MediaPlayer mediaPlayer) {
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
}
示例9: stop
import android.media.MediaPlayer; //導入方法依賴的package包/類
@ReactMethod
public void stop(final Integer key) {
MediaPlayer player = this.playerPool.get(key);
if (player != null && player.isPlaying()) {
player.stop();
}
}
示例10: releaseMemory
import android.media.MediaPlayer; //導入方法依賴的package包/類
public void releaseMemory() {
for(int i=0;i<audioMap.size();i++) {
MediaPlayer mp = audioMap.remove(i);
if (mp.isPlaying()) {
mp.stop();
}
mp.release();
}
audioMap = null;
isPlaying = false;
currentId = CURRENT_NOT_PLAYING;
}
示例11: stopPlaying
import android.media.MediaPlayer; //導入方法依賴的package包/類
@SuppressWarnings({"unused", "UnusedAssignment"})
public static void stopPlaying(MediaPlayer mediaPlayer) {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
}
示例12: onCompletion
import android.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void onCompletion(MediaPlayer mp) {
mPosition = 0;
try {
mp.stop();
isPlaying = false;
if (mCurrentMessage != null) {
mCurrentMessage.isPlaying = false;
}
if (mCallbak != null) {
mCallbak.endAnimation();
mCallbak.onPlayEnd(mCurrentMessage);
mCurrentMessage = null;
mCallbak = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}