當前位置: 首頁>>代碼示例>>Java>>正文


Java OnCompletionListener類代碼示例

本文整理匯總了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();
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:19,代碼來源:RedPacketDialog.java

示例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();
}
 
開發者ID:johnsonsu,項目名稱:react-native-sound-player,代碼行數:23,代碼來源:RNSoundPlayerModule.java

示例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();
    }
  });
}
 
開發者ID:UshalNaidoo,項目名稱:Android-Bubble-Game,代碼行數:17,代碼來源:GamePanel.java

示例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();

    }
  });
}
 
開發者ID:UshalNaidoo,項目名稱:Android-Bubble-Game,代碼行數:17,代碼來源:GamePanel.java

示例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();
        }
    });
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:SportPlayActivity.java

示例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);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:14,代碼來源:VideoPlayerManager.java

示例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();
        }
    });
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:27,代碼來源:VideoPlayActivity.java

示例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();
			}
		}
	});
}
 
開發者ID:zhangjingpu,項目名稱:youkes_vr,代碼行數:28,代碼來源:MediaPlayTools2.java

示例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();
            }
        }
    });
}
 
開發者ID:zhangjingpu,項目名稱:youkes_vr,代碼行數:28,代碼來源:MediaPlayToolsUtil.java

示例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();
    }
}
 
開發者ID:harleensahni,項目名稱:media-button-router,代碼行數:26,代碼來源:ReceiverSelector.java

示例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();
	}

}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:22,代碼來源:RoomChatAdapter.java

示例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();
	}

}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:28,代碼來源:CommonUtils.java

示例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();
}
 
開發者ID:eugenkiss,項目名稱:chanobol,代碼行數:19,代碼來源:FensterVideoView.java

示例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);
		}
	});
}
 
開發者ID:bingoogolapple,項目名稱:Graduation-Design,代碼行數:23,代碼來源:TheftReceiver.java

示例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();
}
 
開發者ID:malmstein,項目名稱:fenster,代碼行數:20,代碼來源:FensterVideoView.java


注:本文中的android.media.MediaPlayer.OnCompletionListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。