Example usage for android.media MediaPlayer isPlaying

List of usage examples for android.media MediaPlayer isPlaying

Introduction

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

Prototype

public native boolean isPlaying();

Source Link

Document

Checks whether the MediaPlayer is playing.

Usage

From source file:Main.java

public static boolean isPlaying(MediaPlayer mp) {
    if (mp != null) {
        return mp.isPlaying();
    }/*from   w  w  w. jav  a  2  s . c  o  m*/
    return false;
}

From source file:Main.java

public static void wait_sound(MediaPlayer _sound) {
    if (_sound != null) {
        while (_sound.isPlaying()) {
            try {
                Thread.sleep(10L);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();//from   w  ww  .j a v  a  2 s .  com
            }
        }
    }
}

From source file:es.deustotech.piramide.utils.tts.TextToSpeechWeb.java

private static synchronized void speech(final Context context, final String text, final String language) {
    executor.submit(new Runnable() {
        @Override/*from   ww w .  j a  v a2s.  co  m*/
        public void run() {
            try {
                final String encodedUrl = Constants.URL + language + "&q="
                        + URLEncoder.encode(text, Encoding.UTF_8.name());
                final DefaultHttpClient client = new DefaultHttpClient();
                HttpParams params = new BasicHttpParams();
                params.setParameter("http.protocol.content-charset", "UTF-8");
                client.setParams(params);
                final FileOutputStream fos = context.openFileOutput(Constants.MP3_FILE,
                        Context.MODE_WORLD_READABLE);
                try {
                    try {
                        final HttpResponse response = client.execute(new HttpGet(encodedUrl));
                        downloadFile(response, fos);
                    } finally {
                        fos.close();
                    }
                    final String filePath = context.getFilesDir().getAbsolutePath() + "/" + Constants.MP3_FILE;
                    final MediaPlayer player = MediaPlayer.create(context.getApplicationContext(),
                            Uri.fromFile(new File(filePath)));
                    player.start();
                    Thread.sleep(player.getDuration());
                    while (player.isPlaying()) {
                        Thread.sleep(100);
                    }
                    player.stop();

                } finally {
                    context.deleteFile(Constants.MP3_FILE);
                }
            } catch (InterruptedException ie) {
                // ok
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:org.artoolkit.ar.samples.ARSimple.ARSimple.java

private static void pause(MediaPlayer media, CountDownTimer timer) {
    if (media != null) {
        if (media.isPlaying()) {
            /*/*from  w  ww. j a  v a2  s  .c  o  m*/
            if (timer != null) {
               timer.cancel();
               timer = null;
            }
            */
            media.pause();
        } else {
            Log.w("MediaPlayer : ", " l'instance n'est pas en mode lecture");
        }
    } else {
        Log.w("MediaPlayer : ", " l'instance n'a pas t initialise");
    }
}

From source file:com.orange.essentials.otb.ui.OtbTermsFragment.java

@Override
public void onPause() {
    super.onPause();
    for (final MediaPlayer player : mPlayers) {
        if (player.isPlaying())
            player.pause();//from   ww  w  .  j a  v  a2  s. com
    }
}

From source file:org.cyanogenmod.theme.chooser.AudiblePreviewFragment.java

private void stopMediaPlayers() {
    if (mContent == null)
        return;//  w w  w  .jav a2  s  . co  m
    final int numChildern = mContent.getChildCount();
    for (int i = 0; i < numChildern; i++) {
        ImageView iv = (ImageView) mContent.getChildAt(i).findViewById(R.id.btn_play_pause);
        if (iv != null) {
            iv.setImageResource(android.R.drawable.ic_media_play);
            MediaPlayer mp = (MediaPlayer) iv.getTag();
            if (mp != null && mp.isPlaying()) {
                mp.pause();
                mp.seekTo(0);
            }
        }
    }
}

From source file:com.joshmoles.byobcontroller.ControlActivity.java

/**
 * Plays raw game audio provided a resource location.
 * @param resource The android resource ID of audio to play.
 *///from ww  w. j  a v a2s.c  o  m
private void playAudio(int resource) {
    MediaPlayer mediaPlayer = MediaPlayer.create(getApplicationContext(), resource);
    mediaPlayer.start();
    while (mediaPlayer.isPlaying())
        android.os.SystemClock.sleep(1000);
    mediaPlayer.release();
    Log.v(Consts.LOAD_FETCH, "Audio released");
}

From source file:com.google.dotorg.crisisresponse.translationcards.RecordingActivity.java

private void finishListening(MediaPlayer mediaPlayer) {
    if (mediaPlayer.isPlaying()) {
        mediaPlayer.stop();/*from   w  ww.j a v a2s .co  m*/
    }
    mediaPlayer.reset();
    mediaPlayer.release();
    recordButton.setBackgroundResource(R.drawable.button_record_enabled);
    listenButton.setBackgroundResource(R.drawable.button_listen_enabled);
    recordingStatus = RecordingStatus.RECORDED;
}

From source file:org.dharmaseed.android.PlayTalkActivity.java

public void playTalkButtonClicked(View view) {
    Log.d(LOG_TAG, "button pressed");
    MediaPlayer mediaPlayer = talkPlayerFragment.getMediaPlayer();
    if (mediaPlayer.isPlaying()) {
        mediaPlayer.pause();/*w  ww  . j  a va 2  s.c o m*/
        setPPButton("ic_media_play");
    } else if (talkPlayerFragment.getMediaPrepared()) {
        mediaPlayer.start();
        setPPButton("ic_media_pause");
    } else {
        try {
            if (talk.isDownloaded()) {
                Log.d(LOG_TAG, "Playing from " + talk.getPath());
                mediaPlayer.setDataSource(talk.getPath());
            } else {
                mediaPlayer.setDataSource(talk.getAudioUrl());
            }
            mediaPlayer.prepareAsync();
        } catch (Exception e) {
            Log.e(LOG_TAG, e.toString());
        }
    }
}

From source file:hku.fyp14017.blencode.ui.controller.SoundController.java

public boolean isSoundPlaying(MediaPlayer mediaPlayer) {
    return mediaPlayer.isPlaying();
}