Java Code Examples for android.media.MediaPlayer#reset()
The following examples show how to use
android.media.MediaPlayer#reset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MissionLine.java From Alite with GNU General Public License v3.0 | 7 votes |
void play(MediaPlayer mp) { if (isPlaying || speechObject == null) { return; } try { isPlaying = true; mp.reset(); if (AliteConfig.HAS_EXTENSION_APK) { mp.setDataSource((String) speechObject); } else { AssetFileDescriptor afd = ((AssetFileDescriptor) speechObject); mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); } mp.setOnCompletionListener(this); mp.prepare(); mp.start(); } catch (IOException e) { AliteLog.e("Error playing speech file", "Error playing speech file", e); } }
Example 2
Source File: OBVideoPlayer.java From GLEXP-Team-onebillion with Apache License 2.0 | 6 votes |
public void stop() { if (player != null) { MediaPlayer cpplayer = player; player = null; finishVideoWait(); try { cpplayer.reset(); cpplayer.release(); } catch (Exception e) { } } }
Example 3
Source File: MultiPlayer.java From MusicPlayer with GNU General Public License v3.0 | 5 votes |
/** * @param player The {@link MediaPlayer} to use * @param path The path of the file, or the http/rtsp URL of the stream * you want to play * @return True if the <code>player</code> has been prepared and is * ready to play, false otherwise */ private boolean setDataSourceImpl(@NonNull final MediaPlayer player, @NonNull final String path) { if (context == null) { return false; } try { player.reset(); player.setOnPreparedListener(null); if (path.startsWith("content://")) { player.setDataSource(context, Uri.parse(path)); } else { player.setDataSource(path); } player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.prepare(); } catch (Exception e) { return false; } player.setOnCompletionListener(this); player.setOnErrorListener(this); final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName()); intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC); context.sendBroadcast(intent); return true; }
Example 4
Source File: MusicPlayer.java From TouchNews with Apache License 2.0 | 5 votes |
private void initiation() { mMediaPlayer = new MediaPlayer(); mMusicList = new ArrayList<>(); mMediaPlayer.reset(); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.setOnErrorListener(this); mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnCompletionListener(this); mMediaPlayer.setOnBufferingUpdateListener(this); }
Example 5
Source File: MultiPlayer.java From VinylMusicPlayer with GNU General Public License v3.0 | 5 votes |
/** * @param player The {@link MediaPlayer} to use * @param path The path of the file, or the http/rtsp URL of the stream * you want to play * @return True if the <code>player</code> has been prepared and is * ready to play, false otherwise */ private boolean setDataSourceImpl(@NonNull final MediaPlayer player, @NonNull final String path) { if (context == null) { return false; } try { player.reset(); player.setOnPreparedListener(null); if (path.startsWith("content://")) { player.setDataSource(context, Uri.parse(path)); } else { player.setDataSource(path); } player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.prepare(); } catch (Exception e) { return false; } player.setOnCompletionListener(this); player.setOnErrorListener(this); final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName()); intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC); context.sendBroadcast(intent); return true; }
Example 6
Source File: MultiPlayer.java From RetroMusicPlayer with GNU General Public License v3.0 | 5 votes |
/** * @param player The {@link MediaPlayer} to use * @param path The path of the file, or the http/rtsp URL of the stream * you want to play * @return True if the <code>player</code> has been prepared and is * ready to play, false otherwise */ private boolean setDataSourceImpl(@NonNull final MediaPlayer player, @NonNull final String path) { if (context == null) { return false; } try { player.reset(); player.setOnPreparedListener(null); if (path.startsWith("content://")) { player.setDataSource(context, Uri.parse(path)); } else { player.setDataSource(path); } player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.prepare(); } catch (Exception e) { return false; } player.setOnCompletionListener(this); player.setOnErrorListener(this); final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName()); intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC); context.sendBroadcast(intent); return true; }
Example 7
Source File: MultiPlayer.java From Phonograph with GNU General Public License v3.0 | 5 votes |
/** * @param player The {@link MediaPlayer} to use * @param path The path of the file, or the http/rtsp URL of the stream * you want to play * @return True if the <code>player</code> has been prepared and is * ready to play, false otherwise */ private boolean setDataSourceImpl(@NonNull final MediaPlayer player, @NonNull final String path) { if (context == null) { return false; } try { player.reset(); player.setOnPreparedListener(null); if (path.startsWith("content://")) { player.setDataSource(context, Uri.parse(path)); } else { player.setDataSource(path); } player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.prepare(); } catch (Exception e) { return false; } player.setOnCompletionListener(this); player.setOnErrorListener(this); final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName()); intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC); context.sendBroadcast(intent); return true; }
Example 8
Source File: WebVideoPresenter.java From Gank.io with GNU General Public License v3.0 | 5 votes |
@Override public void onCompletion(MediaPlayer player) { if (player != null) { if (player.isPlaying()) player.stop(); player.reset(); player.release(); } }
Example 9
Source File: VideoPlayerContainer.java From LLApp with Apache License 2.0 | 5 votes |
@Override public void onCompletion(MediaPlayer mp) { // 播放结束,隐藏该控件 setVisibility(View.GONE); mProgressBar.setProgress(0); mCurrentTimeView.setText("00:00"); mp.reset(); }
Example 10
Source File: LoveVideoView.java From gank.io-unofficial-android-client with Apache License 2.0 | 5 votes |
@Override public void onCompletion(MediaPlayer player) { if (player != null) { if (player.isPlaying()) player.stop(); player.reset(); player.release(); player = null; } }
Example 11
Source File: MusicService.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 5 votes |
@Override public void onCompletion(MediaPlayer mp) { if(player.getCurrentPosition()>0){ mp.reset(); playNext(); } }
Example 12
Source File: MultiPlayer.java From Music-Player with GNU General Public License v3.0 | 5 votes |
/** * @param player The {@link MediaPlayer} to use * @param path The path of the file, or the http/rtsp URL of the stream * you want to play * @return True if the <code>player</code> has been prepared and is * ready to play, false otherwise */ private boolean setDataSourceImpl(@NonNull final MediaPlayer player, @NonNull final String path) { if (context == null) { return false; } try { player.reset(); player.setOnPreparedListener(null); if (path.startsWith("content://")) { player.setDataSource(context, Uri.parse(path)); } else { player.setDataSource(path); } player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.prepare(); } catch (Exception e) { return false; } player.setOnCompletionListener(this); player.setOnErrorListener(this); final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName()); intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC); context.sendBroadcast(intent); return true; }
Example 13
Source File: VideoOutputActivity.java From SimpleVideoEdit with Apache License 2.0 | 5 votes |
@Override public void onCompletion(MediaPlayer mp){ int index = (++playlistIndex) % mSVE.getAllInputClips().size(); try { mp.reset(); mp.setDataSource(mSVE.getAllInputClips().get(index).getClipPath()); mp.prepare(); mp.start(); } catch (IOException e) { } }
Example 14
Source File: WebVideoPresenter.java From gank with GNU General Public License v3.0 | 5 votes |
@Override public void onCompletion(MediaPlayer player) { if (player != null) { if (player.isPlaying()) player.stop(); player.reset(); player.release(); player = null; } }
Example 15
Source File: ServicePlayMusic.java From Bop with Apache License 2.0 | 5 votes |
/** * If something wrong happens with the MusicPlayer. */ @Override public boolean onError(MediaPlayer mp, int what, int extra) { mp.reset(); Log.w(TAG, "onError"); return false; }
Example 16
Source File: NotificationKlaxon.java From boilr with GNU General Public License v3.0 | 4 votes |
public static void start(final Context context, Alarm alarm) { AndroidNotifier notifier = (AndroidNotifier) alarm.getNotifier(); // Make sure we are stop before starting stop(context); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); String alertSound = notifier.getAlertSound(); Uri alertSoundUri = null; if(alertSound != null) alertSoundUri = Uri.parse(alertSound); else alertSoundUri = Uri.parse(sharedPrefs.getString(SettingsFragment.PREF_KEY_DEFAULT_ALERT_SOUND, "")); if(!(Uri.EMPTY).equals(alertSoundUri)) { // Silent or None was selected sMediaPlayer = new MediaPlayer(); sMediaPlayer.setOnErrorListener(new OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { Log.e("Error occurred while playing audio. Stopping NotificationKlaxon."); NotificationKlaxon.stop(context); return true; } }); Integer alertType = notifier.getAlertType(); if(alertType == null) { alertType = Integer.parseInt(sharedPrefs.getString(SettingsFragment.PREF_KEY_DEFAULT_ALERT_TYPE, "")); } try { sMediaPlayer.setDataSource(context, alertSoundUri); startAlarm(context, sMediaPlayer, alertType); } catch(Exception ex) { Log.d("NotificationKlaxon using the fallback ringtone."); // The alarmNoise may be on the sd card which could be busy right // now. Use the fallback ringtone. try { // Must reset the media player to clear the error state. sMediaPlayer.reset(); alertSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); sMediaPlayer.setDataSource(context, alertSoundUri); startAlarm(context, sMediaPlayer, alertType); } catch(Exception ex2) { // At this point we just don't play anything. Log.e("NotificationKlaxon failed to play fallback ringtone.", ex2); } } } Boolean vibrate = notifier.isVibrate(); if(vibrate == null) vibrate = sharedPrefs.getBoolean(SettingsFragment.PREF_KEY_VIBRATE_DEFAULT, true); if(vibrate) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(sVibratePattern, 0); } sStarted = true; }
Example 17
Source File: PlayService.java From music_player with Open Software License 3.0 | 4 votes |
@Override public boolean onError(MediaPlayer mediaPlayer, int i, int i1) { mediaPlayer.reset(); return false; }
Example 18
Source File: MusicService.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 4 votes |
@Override public boolean onError(MediaPlayer mp, int what, int extra) { mp.reset(); return false; }
Example 19
Source File: NewRecordPlayClickListener.java From Conquer with Apache License 2.0 | 4 votes |
/** * 播放语音 * * @Title: playVoice * @Description: TODO * @param @param filePath * @param @param isUseSpeaker * @return void * @throws */ @SuppressWarnings("resource") public void startPlayRecord(String filePath, boolean isUseSpeaker) { if (!(new File(filePath).exists())) { return; } AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mediaPlayer = new MediaPlayer(); if (isUseSpeaker) { audioManager.setMode(AudioManager.MODE_NORMAL); audioManager.setSpeakerphoneOn(true); mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING); } else { audioManager.setSpeakerphoneOn(false);// 关闭扬声器 audioManager.setMode(AudioManager.MODE_IN_CALL); mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL); } // while (true) { // try { // mediaPlayer.reset(); // FileInputStream fis = new FileInputStream(new File(filePath)); // mediaPlayer.setDataSource(fis.getFD()); // mediaPlayer.prepare(); // break; // } catch (IllegalArgumentException e) { // } catch (IllegalStateException e) { // } catch (IOException e) { // } // } // // isPlaying = true; // currentMsg = message; // mediaPlayer.start(); // startRecordAnimation(); // mediaPlayer.setOnCompletionListener(new // MediaPlayer.OnCompletionListener() { // // @Override // public void onCompletion(MediaPlayer mp) { // // TODO Auto-generated method stub // stopPlayRecord(); // } // // }); // currentPlayListener = this; try { mediaPlayer.reset(); // 单独使用此方法会报错播放错误:setDataSourceFD failed.: status=0x80000000 // mediaPlayer.setDataSource(filePath); // 因此采用此方式会避免这种错误 FileInputStream fis = new FileInputStream(new File(filePath)); mediaPlayer.setDataSource(fis.getFD()); mediaPlayer.prepare(); mediaPlayer.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer arg0) { // TODO Auto-generated method stub isPlaying = true; currentMsg = message; arg0.start(); startRecordAnimation(); } }); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub stopPlayRecord(); } }); currentPlayListener = this; // isPlaying = true; // currentMsg = message; // mediaPlayer.start(); // startRecordAnimation(); } catch (Exception e) { BmobLog.i("播放错误:" + e.getMessage()); } }
Example 20
Source File: MusicService.java From Musync with MIT License | 4 votes |
@Override public boolean onError(MediaPlayer mp, int what, int extra) { mp.reset(); return false; }