use of android.media.MediaPlayer in project JamsMusicPlayer by psaravan.
the class AudioPlaybackService method initMediaPlayers.
/**
* Initializes the MediaPlayer objects for this service session.
*/
private void initMediaPlayers() {
/*
* Release the MediaPlayer objects if they are still valid.
*/
if (mMediaPlayer != null) {
mMediaPlayer.release();
mMediaPlayer = null;
}
if (mMediaPlayer2 != null) {
getMediaPlayer2().release();
mMediaPlayer2 = null;
}
mMediaPlayer = new MediaPlayer();
mMediaPlayer2 = new MediaPlayer();
setCurrentMediaPlayer(1);
getMediaPlayer().reset();
getMediaPlayer2().reset();
//Loop the players if the repeat mode is set to repeat the current song.
if (getRepeatMode() == Common.REPEAT_SONG) {
getMediaPlayer().setLooping(true);
getMediaPlayer2().setLooping(true);
}
try {
mMediaPlayer.setWakeMode(mContext, PowerManager.PARTIAL_WAKE_LOCK);
getMediaPlayer2().setWakeMode(mContext, PowerManager.PARTIAL_WAKE_LOCK);
} catch (Exception e) {
mMediaPlayer = new MediaPlayer();
mMediaPlayer2 = new MediaPlayer();
setCurrentMediaPlayer(1);
}
//Set the mediaPlayers' stream sources.
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
getMediaPlayer2().setAudioStreamType(AudioManager.STREAM_MUSIC);
}
use of android.media.MediaPlayer in project android-ocr by rmtheis.
the class BeepManager method buildMediaPlayer.
private static MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
// When the beep has finished playing, rewind to queue up another one.
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer player) {
player.seekTo(0);
}
});
AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
file.close();
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
} catch (IOException ioe) {
Log.w(TAG, ioe);
mediaPlayer = null;
}
return mediaPlayer;
}
use of android.media.MediaPlayer in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSimulatenousEventsAllRun.
@Test
public void testSimulatenousEventsAllRun() {
// Simultaneous events should all run even if
// one of them stops playback.
MediaEvent e1 = new MediaEvent() {
@Override
public void run(MediaPlayer mp, ShadowMediaPlayer smp) {
smp.doStop();
}
};
MediaEvent e2 = Mockito.mock(MediaEvent.class);
info.scheduleEventAtOffset(100, e1);
info.scheduleEventAtOffset(100, e2);
shadowMediaPlayer.setState(INITIALIZED);
shadowMediaPlayer.doStart();
scheduler.advanceBy(100);
// Verify that the first event ran
assertThat(shadowMediaPlayer.isReallyPlaying()).isFalse();
Mockito.verify(e2).run(mediaPlayer, shadowMediaPlayer);
}
use of android.media.MediaPlayer in project glass-progress-bar by pif.
the class MessageDialog method play.
private void play(DialogSound sound) {
int id = R.raw.sound_success;
switch(sound) {
case DISMISS:
id = R.raw.sound_dismiss;
break;
case SUCCESS:
id = R.raw.sound_success;
break;
case ERROR:
id = R.raw.sound_error;
break;
}
if (lastPlayer != null) {
lastPlayer.release();
}
MediaPlayer mediaPlayer = MediaPlayer.create(getContext(), id);
mediaPlayer.setLooping(false);
mediaPlayer.start();
lastPlayer = mediaPlayer;
}
use of android.media.MediaPlayer in project android-app by eoecn.
the class CaptureActivity method initBeepSound.
/**
* 扫描正确后的震动声音,如果感觉apk大了,可以删除
*/
private void initBeepSound() {
if (playBeep && mediaPlayer == null) {
// The volume on STREAM_SYSTEM is not adjustable, and users found it
// too loud,
// so we now play on the music stream.
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(beepListener);
AssetFileDescriptor file = getResources().openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
file.close();
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
} catch (IOException e) {
mediaPlayer = null;
}
}
}
Aggregations