Example usage for android.media MediaPlayer start

List of usage examples for android.media MediaPlayer start

Introduction

In this page you can find the example usage for android.media MediaPlayer start.

Prototype

public void start() throws IllegalStateException 

Source Link

Document

Starts or resumes playback.

Usage

From source file:com.lithiumli.fiction.PlaybackService.java

public void onPrepared(MediaPlayer player) {
    if (mMediaPlayer == null) {
        mMediaPlayer = player;//  ww  w .  j ava  2 s .  c  om
    } else {
        mMediaPlayer.setNextMediaPlayer(player);
        if (mMediaPlayer.isPlaying()) {
            Log.d("fiction", "Was playing");
            mMediaPlayer.stop();
        }
        Log.d("fiction", "Starting music");
        mMediaPlayer.release();
        mMediaPlayer = null;
        mMediaPlayer = player;
    }

    if (acquireAudioFocus()) {
        player.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
        player.start();
        prepareNext();

        mPaused = false;

        showNotification();
    }
}

From source file:com.example.administrator.myapplication2._2_exercise._2_Status_heart.fragments.LeftFragment.java

public void warning() {
    alertCount++;/*from www .  j a v a2s. c om*/
    if (playBool == true && (alertCount % 5 == 0)) {
        MediaPlayer ss1;
        ss1 = MediaPlayer.create(getActivity(), R.raw.alertsound2);
        // ss1.setLooping(true);
        ss1.start();

        Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(2000);

        android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
                getActivity(), R.style.AppCompatAlertDialogStyle);
        builder.setTitle("?? ");
        builder.setMessage(
                "  ? \nMAXIMUM ?\n" + "5 ?? ??.\n"
                        + "?     \n?? .");
        builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                playBool = true;
            }
        });
        builder.show();

        playBool = false;
    }
}

From source file:it.interfree.leonardoce.bootreceiver.AlarmKlaxon.java

private void startAlarm(MediaPlayer player)
        throws java.io.IOException, IllegalArgumentException, IllegalStateException {
    final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    // Non deve suonare se il cellulare e' silenzioso
    Log.v(LTAG, "Stato del telefono: " + audioManager.getRingerMode());

    // do not play alarms if stream volume is 0
    // (typically because ringer mode is silent).
    if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0
            && audioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT
            && audioManager.getRingerMode() != AudioManager.RINGER_MODE_VIBRATE) {
        player.setAudioStreamType(AudioManager.STREAM_ALARM);
        player.setLooping(true);/*w w w  .j a va  2  s  .com*/
        player.prepare();
        player.start();
    }
}

From source file:com.android.onemedia.playback.LocalRenderer.java

@Override
public void onPrepared(MediaPlayer player) {
    if (!isCurrentPlayer(player)) {
        return;/*www . j a v a  2  s. c o m*/
    }
    setState(STATE_READY);
    if (DEBUG) {
        Log.d(TAG, mDebugId + ": Finished preparing, seekOnReady is " + mSeekOnReady);
    }
    if (mSeekOnReady >= 0) {
        onSeekTo(mSeekOnReady);
        mSeekOnReady = -1;
    }
    if (mPlayOnReady) {
        player.start();
        setState(STATE_PLAYING);
    }
}

From source file:com.saulcintero.moveon.services.MoveOnService.java

private void playSound(int id) {
    switch (id) {
    case 1:/*www .j  a v a 2  s.  co  m*/
        mMediaPlayer = MediaPlayer.create(this, R.raw.beep);
        break;
    case 2:
        mMediaPlayer = MediaPlayer.create(this, R.raw.coach_whistle);
        break;
    }

    mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mp.start();
        }
    });

    mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            mp.stop();
            mp.release();
        }
    });
}

From source file:net.ddns.mlsoftlaberge.trycorder.TryviscamFragment.java

private void buttonbad() {
    MediaPlayer mediaPlayer = MediaPlayer.create(getActivity().getBaseContext(), R.raw.denybeep1);
    mediaPlayer.start(); // no need to call prepare(); create() does that for you
}

From source file:com.hhunj.hhudata.ForegroundService.java

private MediaPlayer ring() throws Exception, IOException {

    Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    MediaPlayer player = new MediaPlayer();

    player.setDataSource(this, alert);

    final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    if (audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION) != 0) {

        player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);

        player.setLooping(true);//from  ww  w  .  ja va  2  s.  c  o  m

        player.prepare();

        player.start();

    }

    return player;

}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void playSound(int soundID) {
    MediaPlayer mediaPlayer = MediaPlayer.create(this, soundID);
    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override/*w ww.j a v a  2  s  .c o  m*/
        public void onCompletion(MediaPlayer mp) {
            mp.release();
        }
    });
    mediaPlayer.start();
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public void playBackMusic(TaskManagerParms taskMgrParms, EnvironmentParms envParms,
        CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String action, String dlg_id,
        String fp, String vol_left, String vol_right) {
    ar.action_resp = ActionResponse.ACTION_SUCCESS;
    File lf = new File(fp);
    if (!lf.exists()) {
        ar.action_resp = ActionResponse.ACTION_ERROR;
        ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_play_sound_notfound, fp);
        return;/*from  w  w  w .  j  ava2s.  c  om*/
    }
    if (!isRingerModeNormal(envParms)) {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_ignore_sound_ringer_not_normal;
        return;
    }
    MediaPlayer player = MediaPlayer.create(taskMgrParms.context, Uri.parse(fp));
    taskResponse.active_action_name = action;

    if (player != null) {
        int duration = player.getDuration();
        TaskManager.showMessageDialog(taskMgrParms, envParms, util, taskResponse.active_group_name,
                taskResponse.active_task_name, taskResponse.active_action_name, taskResponse.active_dialog_id,
                MESSAGE_DIALOG_MESSAGE_TYPE_SOUND, fp);

        if (!vol_left.equals("-1") && !vol_left.equals(""))
            player.setVolume(Float.valueOf(vol_left) / 100, Float.valueOf(vol_right) / 100);
        player.start();
        waitTimeTc(taskResponse, duration + 10);
        if (!taskResponse.active_thread_ctrl.isEnable()) {
            ar.action_resp = ActionResponse.ACTION_CANCELLED;
            ar.resp_msg_text = "Action was cancelled";
        }
        player.stop();
        player.release();
        TaskManager.closeMessageDialog(taskMgrParms, envParms, util, taskResponse);
    } else {
        ar.action_resp = ActionResponse.ACTION_ERROR;
        ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_play_sound_error, fp);
    }
}

From source file:net.ddns.mlsoftlaberge.trycorder.contacts.ContactAdminFragment.java

private void buttonsound() {
    MediaPlayer mediaPlayer = MediaPlayer.create(getActivity().getBaseContext(), R.raw.keyok2);
    mediaPlayer.start(); // no need to call prepare(); create() does that for you
}