本文整理匯總了Java中android.media.MediaPlayer.OnCompletionListener類的典型用法代碼示例。如果您正苦於以下問題:Java OnCompletionListener類的具體用法?Java OnCompletionListener怎麽用?Java OnCompletionListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
OnCompletionListener類屬於android.media.MediaPlayer包,在下文中一共展示了OnCompletionListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: soundShake
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
private void soundShake() {
try {
this.mPlayer = MediaPlayer.create(RedPacketSdkManager.getInstance().getApplicationContext(), R.raw.shake_sound);
if (this.mPlayer != null) {
this.mPlayer.start();
this.mPlayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
RedPacketDialog.this.mPlayer.release();
}
});
}
} catch (Exception e) {
e.printStackTrace();
if (this.mPlayer != null) {
this.mPlayer.release();
}
}
}
示例2: playSoundFile
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
@ReactMethod
public void playSoundFile(String name, String type) throws IOException {
if (this.mediaPlayer == null) {
int soundResID = getReactApplicationContext().getResources().getIdentifier(name, "raw", getReactApplicationContext().getPackageName());
this.mediaPlayer = MediaPlayer.create(getCurrentActivity(), soundResID);
this.mediaPlayer.setOnCompletionListener(
new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer arg0) {
WritableMap params = Arguments.createMap();
params.putBoolean("success", true);
sendEvent(getReactApplicationContext(), "FinishedPlaying", params);
}
});
} else {
Uri uri = Uri.parse("android.resource://" + getReactApplicationContext().getPackageName() + "/raw/" + name);
this.mediaPlayer.reset();
this.mediaPlayer.setDataSource(getCurrentActivity(), uri);
this.mediaPlayer.prepare();
}
this.mediaPlayer.start();
}
示例3: chimeSound
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
public static void chimeSound() {
((Activity) MainMenu.getAppContext()).runOnUiThread(new Runnable() {
public void run() {
final MediaPlayer mp1 = MediaPlayer.create(MainMenu.getAppContext(), R.raw.chime);
mp1.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp1.release();
}
});
mp1.start();
}
});
}
示例4: popSound
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
public static void popSound() {
((Activity) MainMenu.getAppContext()).runOnUiThread(new Runnable() {
public void run() {
final MediaPlayer mp2 = MediaPlayer.create(MainMenu.getAppContext(), R.raw.bub_pop);
mp2.setVolume(0,1);
mp2.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp2.release();
}
});
mp2.start();
}
});
}
示例5: initViews
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
protected void initViews() {
this.mVideoView = (ExVideoView) findViewById(R.id.video);
this.mHeaderView = findViewById(R.id.header);
this.mBtnBack = findViewById(R.id.btn_back);
this.mVideoView.setExpandState(true);
this.mVideoView.setStatus(2);
this.mVideoView.setContinueVideo(this.mUri);
this.mVideoView.getVideoView().setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
SportPlayActivity.this.setResult(-1);
SportPlayActivity.this.finish();
}
});
this.mVideoView.getControllerView().addBindView(this.mHeaderView);
this.mBtnBack.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SportPlayActivity.this.onBackPressed();
}
});
}
示例6: initPlayer
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
public static void initPlayer(VideoView videoView, OnPreparedListener onPreparedListener,
OnCompletionListener onCompletionListener, OnErrorListener
onErrorListener) {
if (onPreparedListener != null) {
videoView.setOnPreparedListener(onPreparedListener);
}
if (onCompletionListener != null) {
videoView.setOnCompletionListener(onCompletionListener);
}
if (onErrorListener != null) {
videoView.setOnErrorListener(onErrorListener);
}
}
示例7: initVideoData
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
private void initVideoData() {
if (this.mentionIndex >= this.totalMetionCount) {
lessonFinish();
return;
}
this.currentMention = (Mention) this.mentionList.get(this.mentionIndex);
this.videoPath = this.videoDownloadHelper.getVideoName(this.ctx, this.currentMention.id);
this.videoView.setVideoPath(this.videoPath);
this.videoView.setOnErrorListener(new OnErrorListener() {
public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
VideoPlayActivity.this.onPlayError();
return true;
}
});
this.videoView.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
if (VideoPlayActivity.this.currentMention.is_times && !VideoPlayActivity.this
.isMentionComplete() && VideoPlayActivity.this.isCounting) {
VideoPlayActivity.this.handler.post(VideoPlayActivity.this.countDownRunnable);
VideoPlayActivity.this.playCountNum = VideoPlayActivity.this.playCountNum + 1;
}
VideoPlayActivity.this.videoView.seekTo(0);
VideoPlayActivity.this.videoView.start();
}
});
}
示例8: setOnCompletionListener
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
/**
*
* <p>Title: setOnCompletionListener</p>
* <p>Description: Set the playback end of speech monitoring,
* again will play the status is set to an initial state</p>
* @see com.youkes.vr.common.utils.MediaPlayTools#status
* {@link com.youkes.vr.common.utils.MediaPlayTools#STATUS_ERROR}
* {@link com.youkes.vr.common.utils.MediaPlayTools#STATUS_PLAYING}
* {@link com.youkes.vr.common.utils.MediaPlayTools#STATUS_PAUSE}
* {@link com.youkes.vr.common.utils.MediaPlayTools#STATUS_STOP}
*/
private void setOnCompletionListener() {
//
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
LogUtil.d(TAG, "[MediaPlayTools - setOnCompletionListener] Play file[" + urlPath+ "] com");
status = STATUS_STOP;
if(mListener != null) {
mListener.OnVoicePlayCompletion();
}
}
});
}
示例9: setOnCompletionListener
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
/**
*
* <p>Title: setOnCompletionListener</p>
* <p>Description: Set the playback end of speech monitoring,
* again will play the status is set to an initial state</p>
* @see com.youkes.vr.common.utils.MediaPlayTools#status
* {@link com.youkes.vr.common.utils.MediaPlayTools#STATUS_ERROR}
* {@link com.youkes.vr.common.utils.MediaPlayTools#STATUS_PLAYING}
* {@link com.youkes.vr.common.utils.MediaPlayTools#STATUS_PAUSE}
* {@link com.youkes.vr.common.utils.MediaPlayTools#STATUS_STOP}
*/
private void setOnCompletionListener() {
//
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
LogUtil.d(TAG, "[MediaPlayTools - setOnCompletionListener] Play file[" + urlPath+ "] com");
status = STATUS_STOP;
if(mListener != null) {
mListener.OnVoicePlayCompletion();
}
}
});
}
示例10: onTimeout
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
/**
* Takes appropriate action to notify user and dismiss activity on timeout.
*/
private void onTimeout() {
Log.d(TAG, "Media Button Selector: Timed out waiting for user interaction, finishing activity");
final MediaPlayer timeoutPlayer = MediaPlayer.create(this, R.raw.dismiss);
timeoutPlayer.start();
// not having an on error listener results in on completion listener
// being called anyway
timeoutPlayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
timeoutPlayer.release();
}
});
// If the user has set their preference not to confirm actions, we'll
// just forward automatically to whoever was last selected. If no one is
// selected, it just acts like finish anyway.
if (preferences.getBoolean(Constants.CONFIRM_ACTION_PREF_KEY, true)) {
finish();
} else {
select();
}
}
示例11: playMusic
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
private void playMusic(String name) {
try {
if (mMediaPlayer.isPlaying()) {
mMediaPlayer.stop();
}
System.out.println(name + "haha");
mMediaPlayer.reset();
mMediaPlayer.setDataSource(name);
mMediaPlayer.prepare();
mMediaPlayer.start();
mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: playMusic
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
/**
* ��������
*
* @param name
*/
public static void playMusic(String name) {
try {
if (mMediaPlayer.isPlaying()) {
mMediaPlayer.stop();
}
mMediaPlayer.reset();
mMediaPlayer.setDataSource(name);
mMediaPlayer.prepare();
mMediaPlayer.start();
mMediaPlayer.setVolume((float) 0.81, (float) 0.82);
mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
示例13: createErrorDialog
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
private static AlertDialog createErrorDialog(final Context context, final OnCompletionListener completionListener, final MediaPlayer mediaPlayer, final int errorMessage) {
return new AlertDialog.Builder(context)
.setMessage(errorMessage)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int whichButton) {
/* If we get here, there is no onError listener, so
* at least inform them that the video is over.
*/
if (completionListener != null) {
completionListener.onCompletion(mediaPlayer);
}
}
}
)
.setCancelable(false)
.create();
}
示例14: playAlarm
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
/**
* 播放報警音樂
*
* @param context
*/
private void playAlarm(Context context) {
final AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
final int currentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), AudioManager.FLAG_PLAY_SOUND);
Logger.i(TAG, "播放報警音樂");
MediaPlayer player = MediaPlayer.create(context, R.raw.alarm);
player.setLooping(false);
player.start();
player.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume, AudioManager.FLAG_PLAY_SOUND);
}
});
}
示例15: createErrorDialog
import android.media.MediaPlayer.OnCompletionListener; //導入依賴的package包/類
private static AlertDialog createErrorDialog(final Context context, final OnCompletionListener completionListener, final MediaPlayer mediaPlayer, final int errorMessage) {
return new AlertDialog.Builder(context)
.setMessage(errorMessage)
.setPositiveButton(
android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int whichButton) {
/* If we get here, there is no onError listener, so
* at least inform them that the video is over.
*/
if (completionListener != null) {
completionListener.onCompletion(mediaPlayer);
}
}
}
)
.setCancelable(false)
.create();
}