本文整理汇总了Java中android.media.MediaPlayer.isPlaying方法的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer.isPlaying方法的具体用法?Java MediaPlayer.isPlaying怎么用?Java MediaPlayer.isPlaying使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.isPlaying方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playAllAsync
import android.media.MediaPlayer; //导入方法依赖的package包/类
public void playAllAsync() {
Thread r = new Thread() {
@Override
public void run() {
int counter = 0;
for (MediaPlayer m : loadedSounds) {
Log.d(MainActivity.LOG_TAG, "Playing sound no. " + counter);
m.start();
while (m.isPlaying()) {
try {
Thread.sleep(100,0); // lower cpu if we wait and not just busy wait
} catch (InterruptedException e) { e.printStackTrace();}
}
counter++;
}
raisePlayBackFinishEvent();
}
};
r.start();
}
示例2: resume
import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
* resume playing
*
* @return
*/
public synchronized UDAudio resume() {
final MediaPlayer player = getMediaPlayer();
if (player != null && player.isPlaying() == false) {
try {
if (player.getCurrentPosition() > 0) {
player.start();
} else {
play(mUriOrName, mLoopTimes);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return this;
}
示例3: 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;
}
示例4: 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();
}
}
示例5: onPrepared
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onPrepared(MediaPlayer mp) {
if (mp != null) {
synchronized (mp) {
try {
if (mp.isPlaying() == false) {
mp.start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
示例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: voicePause
import android.media.MediaPlayer; //导入方法依赖的package包/类
public static void voicePause(MediaPlayer player, Chronometer chronometer) {
// 判断音乐是否在播放
if (player != null && player.isPlaying()) {
setChronometer(chronometer, Constant.CHRONOMETER_STOP);
// 暂停音乐播放器
player.pause();
}
}
示例9: onPrepared
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
progress_bar.setVisibility(View.GONE);
onVideoSizeChanged(mediaPlayer);
if (!mediaPlayer.isPlaying()) {
isPlay = true;
mediaPlayer.start();
}
}
示例10: 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;
}
}
示例11: pause
import android.media.MediaPlayer; //导入方法依赖的package包/类
@ReactMethod
public void pause(final Integer key) {
MediaPlayer player = this.playerPool.get(key);
if (player != null && player.isPlaying()) {
player.pause();
}
}
示例12: 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();
}
}
示例13: 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;
}
示例14: play
import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
* start playing audio
*
* @param uriOrName
* @param loopTimes
* @return
*/
public synchronized UDAudio play(String uriOrName, Integer loopTimes) {
stopAndReset();
if (uriOrName != null && uriOrName.equals(this.mUriOrName) == false) {//url 不同
this.mUriOrName = uriOrName;
}
if (loopTimes != null) {
this.mLoopTimes = loopTimes;
}
if (this.mUriOrName != null) {
final MediaPlayer player = getMediaPlayer();
if (player != null && player.isPlaying() == false) {
String uri = null;
boolean assetFileExist = false;
if (URLUtil.isNetworkUrl(this.mUriOrName) || URLUtil.isFileUrl(this.mUriOrName) || URLUtil.isAssetUrl(this.mUriOrName)) {//net & file & asset
uri = this.mUriOrName;
} else {//plain text, use as file path
uri = getLuaResourceFinder().buildFullPathInBundleOrAssets(this.mUriOrName);
assetFileExist = AssetUtil.exists(getContext(), uri);
}
try {
if (assetFileExist) {
final AssetFileDescriptor descriptor = getContext().getAssets().openFd(uri);
player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
} else {
player.setDataSource(uri);
}
player.setOnErrorListener(this);
player.setOnCompletionListener(this);
player.setOnPreparedListener(this);
player.setLooping((this.mLoopTimes != null && this.mLoopTimes > 1) ? true : false);
player.prepareAsync();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return this;
}
示例15: onCompletion
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
if (null!=mPlayer && !mPlayer.isPlaying() && mPlayer.getCurrentPosition()+200>=mPlayer.getDuration()) {
int musicOrder = mConfigModel.getMusicOrder();
switch (musicOrder) {
case CONST.MUSIC_ORDER_SINGLE:
setCurrentPosition(mPosition);
if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
mHandler.post(new Runnable() {
@Override
public void run() {
if (null != onTrackListener) {
onTrackListener.onPlayStateChange(mPlayer.isPlaying());
}
}
});
}
break;
case CONST.MUSIC_ORDER_LIST:
nextMusic();
break;
case CONST.MUSIC_ORDER_RANDOM:
Random random = new Random();
int position = random.nextInt(mCurrentPlaylist.size());
setCurrentPosition(position);
if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
}
mHandler.post(new Runnable() {
@Override
public void run() {
if (null != onTrackListener) {
onTrackListener.onPlayStateChange(mPlayer.isPlaying());
}
}
});
break;
}
}
}