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(); } } }
@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(); }
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(); } }); }
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(); } }); }
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(); } }); }
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(); } }); }
/** * * <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(); } } }); }
/** * 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(); } }
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(); } }
/** * �������� * * @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(); } }
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(); }
/** * 播放报警音乐 * * @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); } }); }
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(); }
public static void playNotification(Activity myActivity) { Uri defaultRingtoneUri = RingtoneManager .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); try { MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setDataSource(myActivity.getBaseContext(), defaultRingtoneUri); mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); mediaPlayer.prepare(); mediaPlayer.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer mp) { mp.release(); } }); mediaPlayer.start(); } catch (Exception e) { e.printStackTrace(); } }
public static void playSound(Activity activity) { int randomInt = new Random().nextInt(4); String fileName = "groot/groot" + randomInt + ".mp3"; // XposedBridge.log(TAG + ": " + fileName); try { File mp3File = new File(Environment.getExternalStorageDirectory(), fileName); Uri mp3Uri = Uri.fromFile(mp3File); MediaPlayer mediaPlayer = MediaPlayer.create(activity, mp3Uri); mediaPlayer.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.release(); } }); mediaPlayer.start(); } catch (Exception e) { // TODO: handle exception } }
private void startPlaying(Uri uri) { mPlayer = new MediaPlayer(); try { mPlayer.setDataSource(getActivity(), uri); mPlayer.prepare(); mPlayer.start(); mPlayer.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mPlayer = null; ((ImageView)isPlayingView.findViewById(R.id.gridview_item_picture)).setImageBitmap(recordingBitmap); recordingBitmap = null; isPlayingView = null; } }); } catch (IOException e) { Log.e(Constants.TAG, "prepare() failed"); } }
public void closeAudioMediaPlayer() { if (mMediaPlayerAudio == null) { return; } if (mMediaPlayerAudio.isPlaying()) { mMediaPlayerAudio .setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mMediaPlayerAudio.reset(); mMediaPlayerAudio.release(); mMediaPlayerAudio = null; } }); } else { mMediaPlayerAudio.release(); mMediaPlayerAudio = null; } }
/** * Plays the specified sound from the application asset folder. * * @param context * @param assetSoundPath Path to the sound in the assets folder. */ public static void media_soundPlayFromAssetFolder(Context context, String assetSoundPath){ try { AssetFileDescriptor afd = context.getAssets().openFd(assetSoundPath); MediaPlayer player = new MediaPlayer(); player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); player.prepare(); player.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.release(); } }); player.start(); } catch (Exception e) { if(LOG_ENABLE){ Log.e(TAG, "Error playing sound: '" + assetSoundPath + "' (" + e.getMessage() + ")", e); } } }
/** * Plays the specified sound. * * @param context * @param soundId The resource to play. */ public static void media_soundPlay(Context context, int soundId){ try { //int fileResourceId = context.getResources().getIdentifier(rawSoundPath,"raw", context.getPackageName()); MediaPlayer player = MediaPlayer.create(context, soundId); player.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.reset(); mp.release(); mp = null; } }); player.start(); } catch (Exception e) { if(LOG_ENABLE){ Log.e(TAG, "Error playing sound (" + e.getMessage() + ")", e); } } }
/** * Plays the specified filename of the RAW Android folder. * * @param context * @param rawSoundName The filename without the extension in the raw folder. */ public static void media_soundPlayFromRawFolder(Context context, String rawSoundName){ try { int fileResourceId = context.getResources().getIdentifier(rawSoundName,"raw", context.getPackageName()); MediaPlayer player = MediaPlayer.create(context, fileResourceId); player.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.release(); } }); player.start(); } catch (Exception e) { if(LOG_ENABLE){ Log.e(TAG, "Error playing sound (" + e.getMessage() + ")", e); } } }
@Override public void play(final String fileName, boolean resumeIfPlaying) { try { if (resumeIfPlaying && mediaPlayer != null && playing != null && playing.equals(fileName)) { if (!mediaPlayer.isPlaying()) mediaPlayer.start(); } else { if (mediaPlayer == null) { mediaPlayer = new MediaPlayer(); } mediaPlayer.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mediaPlayer.setOnCompletionListener(null); prepare(fileName + "_main.mp3", true); } }); prepare(fileName + "_intro.mp3", false); } } catch (Exception e) { Modules.LOG.error(TAG, e.toString()); } }
private void initMediaPlayer(){ mPlayer = new MediaPlayer(); OnCompletionListener doneListener = new OnCompletionListener(){ @Override public void onCompletion(MediaPlayer mPlayer) { ((Button) findViewById(R.id.button_play)).setText(R.string.play_button); } }; try{ mPlayer.setDataSource(QuizActivity.getRecordingFilename()); mPlayer.setOnCompletionListener(doneListener); mPlayer.prepare(); } catch (IOException e){ //TODO more here e.printStackTrace(); } }
public void playDesMusic(Context context, String name, OnCompletionListener onCompletionListener) { try { desMediaPlayer.reset(); if (name.contains(VideoDownloadHelper.AUDIO_NAME)) { String path = VideoDownloadHelper.getInstance().getAudioDownloadPath(context) + name; File file = new File(path); if ((file == null || !file.exists() || file.length() == 0) && this.onPrepareError != null) { this.onPrepareError.onPrepareError(); return; } desMediaPlayer.setDataSource(path); } else { AssetFileDescriptor descriptor = context.getAssets().openFd("sport_audio/" + name + VideoDownloadHelper.AUDIO_FORMAT); desMediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor .getStartOffset(), descriptor.getLength()); descriptor.close(); } desMediaPlayer.prepare(); desMediaPlayer.start(); desMediaPlayer.setOnCompletionListener(onCompletionListener); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e2) { e2.printStackTrace(); } }
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); } }
private void lessonFinish() { stopLesson(); this.desPlayerManager.playDesMusic(this, "d_lesson_done", new OnCompletionListener() { public void onCompletion(MediaPlayer mp) { VideoPlayActivity.this.removeCallbacks(); VideoPlayActivity.this.stopLesson(); VideoPlayActivity.this.postProgress(); } }); }
private void playDesMusic() { if (this.desMusics.size() != 0 && this.desMusicIndex <= this.desMusics.size() - 1) { this.desPlayerManager.playDesMusic(this.ctx, (String) this.desMusics.get(this .desMusicIndex), new OnCompletionListener() { public void onCompletion(MediaPlayer mp) { if (VideoPlayActivity.this.desMusicIndex == VideoPlayActivity.this.desMusics .size() - 1) { VideoPlayActivity.this.desMusics.clear(); VideoPlayActivity.this.desMusicIndex = 0; VideoPlayActivity.this.isCounting = true; VideoPlayActivity.this.videoView.seekTo(0); VideoPlayActivity.this.videoView.start(); VideoPlayActivity.this.startMentionTime(); if (VideoPlayActivity.this.currentMention.is_times) { VideoPlayActivity.this.handler.post(VideoPlayActivity.this .countDownRunnable); } else { VideoPlayActivity.this.handler.post(VideoPlayActivity.this .timeCountDownRunnable); } VideoPlayActivity.this.refreshMentionCount((VideoPlayActivity.this .playCountNum >= 10 ? Integer.valueOf(VideoPlayActivity.this .playCountNum) : "0" + VideoPlayActivity.this.playCountNum) + "/" + VideoPlayActivity.this.currentMention.number); return; } VideoPlayActivity.this.desMusicIndex = VideoPlayActivity.this.desMusicIndex + 1; VideoPlayActivity.this.playDesMusic(); } }); } }
public void setCallback(final Runnable callback, boolean loop) { this.loop = loop; player.setLooping(loop); if (!loop) { player.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { callback.run(); } }); } else { player.setOnCompletionListener(null); } }
/** * * * Add custom playback completion listener. Adding multiple listeners will queue up all the * listeners and fire them on media playback completes. */ public AudioWife addOnCompletionListener(OnCompletionListener listener) { // add default click listener to the top // so that it is the one that gets fired first mCompletionListeners.add(0, listener); return this; }
public Music play(Context context, List<Music> list, int position) { // 如果有正在播放的歌曲,将它停止 if (playing == Config.PLAYING_PLAY) { media.reset(); } media = MediaPlayer.create(context, Uri.parse("file://" + list.get(position).getPath())); try { media.start(); this.list = list; this.position = position; this.context = context; media.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { Player.this.context.sendBroadcast(new Intent( Config.RECEIVER_MUSIC_CHANGE)); completion(Player.this.context, Player.this.list, Player.this.position); } }); playing = Config.PLAYING_PLAY; context.sendBroadcast(new Intent(Config.RECEIVER_MUSIC_CHANGE)); } catch (NullPointerException e) { ViewInject.toast("亲,找不到歌曲了,存储卡拔掉了吗?"); } return list.get(position); }
public void setOnCompletionListener(OnCompletionListener listener) { System.out.println("OnCompletionList..."); Platform.runLater(new Runnable() { @Override public void run() { try { if (mediaPlayer != null) { mediaPlayer.stop(); } } catch (Exception e) { System.out.println("SetOnCompletionListener\nError Player Video: " + e.toString()); } } }); }
/**** * Add custom playback completion listener. Adding multiple listeners will queue up all the * listeners and fire them on media playback completes. */ public AudioWife addOnCompletionListener(OnCompletionListener listener) { // add default click listener to the top // so that it is the one that gets fired first mCompletionListeners.add(0, listener); return this; }
public void FinishListener(){ s.sounds(Main.song[i]); s.play(); s.mp.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mPlayer) { mPlayer.stop(); s.isPlaying = false; play.setVisibility(View.VISIBLE); pause.setVisibility(View.GONE); } }); }
/** * {@inheritDoc} */ @Override public void setOnCompletionListener(final OnCompletionListener listener) { if (mCompatMode) { mCompletion = listener; } else { super.setOnCompletionListener(listener); } }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View v = getActivity().getLayoutInflater() .inflate(R.layout.fragment_play_video, null); mVideoView = (VideoView)v.findViewById(R.id.hellomoon_playVideoView); Uri resourceUri = Uri.parse("android.resource://org.mazhuang.android.hellomoon/" + R.raw.vid_20150110_211545); //File file = new File("/sdcard/Download/vid_20150110_211545.mp4"); mMediaController = new MediaController(getActivity()); mVideoView.setMediaController(mMediaController); mMediaController.setMediaPlayer(mVideoView); //mVideoView.setVideoPath(file.getAbsolutePath()); mVideoView.setVideoURI(resourceUri); mVideoView.requestFocus(); mVideoView.start(); mVideoView.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { PlayVideoFragment.this.dismiss(); } }); return new AlertDialog.Builder(getActivity()) .setView(v) .create(); }
private void playSound() { MediaPlayer player = MediaPlayer.create(this, R.raw.crystal_ball); player.start(); player.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.release(); } }); }
private void playIntro() { runOnUiThread(new Runnable() { public void run() { splashBackgroundView.setVisibility(View.GONE); videoContainer.setVisibility(View.VISIBLE); videoView.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { videoView.stopPlayback(); videoView.setEnabled(false); videoContainer.setVisibility(View.GONE); startActivity(new Intent(SplashActivity.this, ConnectActivity.class)); finish(); return true; } }); videoView.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer mp) { proceedToNextActivity(); } }); videoView.start(); } }); }