本文整理汇总了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();
}
}