use of android.media.MediaPlayer in project kickmaterial by byoutline.
the class VideoActivity method setDataFromArgs.
private void setDataFromArgs() {
Intent intent = getIntent();
if (intent == null) {
// NOI18E
LogUtils.LOGE(TAG, "Null intent");
return;
}
Bundle args = intent.getExtras();
if (args == null) {
// NOI18E
LogUtils.LOGE(TAG, "Null args");
return;
}
String videoUrl = args.getString(BUNDLE_VIDEO_URL);
String altVideoUrl = args.getString(BUNDLE_ALT_VIDEO_URL);
String webviewUrl = args.getString(BUNDLE_WEBVIEW_URL);
Uri uri = Uri.parse(videoUrl);
videoView.setMediaController(new VideoController(this, webviewUrl));
videoView.setVideoURI(uri);
videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
boolean tryAltVideo = !TextUtils.isEmpty(altVideoUrl);
@Override
public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
if (tryAltVideo) {
tryAltVideo = false;
videoView.setVideoURI(Uri.parse(altVideoUrl));
videoView.start();
return true;
}
return false;
}
});
videoView.setOnCompletionListener(mediaPlayer -> finish());
videoView.requestFocus();
}
use of android.media.MediaPlayer in project zxingfragmentlib by mitoyarzun.
the class BeepManager method buildMediaPlayer.
private MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnErrorListener(this);
// mediaPlayer.release();
return null;
// }
}
use of android.media.MediaPlayer in project Signal-Android by WhisperSystems.
the class IncomingRinger method createPlayer.
private MediaPlayer createPlayer() {
try {
MediaPlayer mediaPlayer = new MediaPlayer();
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
mediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
mediaPlayer.setDataSource(context, ringtoneUri);
mediaPlayer.setLooping(true);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
return mediaPlayer;
} catch (IOException e) {
Log.e(TAG, "Failed to create player for incoming call ringer");
return null;
}
}
use of android.media.MediaPlayer in project Lazy by l123456789jy.
the class RecorderControl method startPlaying.
/**
*
* @param Filename Filename
* @param completion completion
*/
//
public void startPlaying(String Filename, OnCompletionListener completion) {
if (!playState) {
if (mPlayer == null) {
mPlayer = new MediaPlayer();
}
try {
mPlayer.setDataSource(Filename);
mPlayer.prepare();
playState = true;
mPlayer.start();
mPlayer.setOnCompletionListener(completion);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
if (mPlayer.isPlaying()) {
mPlayer.stop();
playState = false;
// startPlaying(Filename);
} else {
playState = false;
}
}
}
use of android.media.MediaPlayer in project Signal-Android by WhisperSystems.
the class AudioSlidePlayer method play.
public void play(final double progress) throws IOException {
if (this.mediaPlayer != null)
return;
this.mediaPlayer = new MediaPlayer();
this.audioAttachmentServer = new AttachmentServer(context, masterSecret, slide.asAttachment());
audioAttachmentServer.start();
mediaPlayer.setDataSource(context, audioAttachmentServer.getUri());
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
Log.w(TAG, "onPrepared");
synchronized (AudioSlidePlayer.this) {
if (mediaPlayer == null)
return;
if (progress > 0) {
mediaPlayer.seekTo((int) (mediaPlayer.getDuration() * progress));
}
mediaPlayer.start();
setPlaying(AudioSlidePlayer.this);
}
notifyOnStart();
progressEventHandler.sendEmptyMessage(0);
}
});
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.w(TAG, "onComplete");
synchronized (AudioSlidePlayer.this) {
mediaPlayer = null;
if (audioAttachmentServer != null) {
audioAttachmentServer.stop();
audioAttachmentServer = null;
}
}
notifyOnStop();
progressEventHandler.removeMessages(0);
}
});
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.w(TAG, "MediaPlayer Error: " + what + " , " + extra);
Toast.makeText(context, R.string.AudioSlidePlayer_error_playing_audio, Toast.LENGTH_SHORT).show();
synchronized (AudioSlidePlayer.this) {
mediaPlayer = null;
if (audioAttachmentServer != null) {
audioAttachmentServer.stop();
audioAttachmentServer = null;
}
}
notifyOnStop();
progressEventHandler.removeMessages(0);
return true;
}
});
mediaPlayer.prepareAsync();
}
Aggregations