Example usage for android.media MediaPlayer setLooping

List of usage examples for android.media MediaPlayer setLooping

Introduction

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

Prototype

public native void setLooping(boolean looping);

Source Link

Document

Sets the player to be looping or non-looping.

Usage

From source file:com.metinkale.prayerapp.vakit.AlarmReceiver.java

public static MediaPlayer play(Context c, String sound) throws IOException {
    Uri uri = Uri.parse(sound);//from   w  w  w  . ja v a2s.  c  o m

    MediaPlayer mp = new MediaPlayer();
    mp.setLooping(false);
    mp.setDataSource(c, uri);
    mp.setAudioStreamType(getStreamType(c));

    mp.prepare();
    mp.start();
    return mp;
}

From source file:org.fdroid.enigtext.notifications.MessageNotifier.java

private static void sendInThreadNotification(Context context) {
    try {//w w  w  . jav  a 2 s .c o  m
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

        if (!sp.getBoolean(ApplicationPreferencesActivity.IN_THREAD_NOTIFICATION_PREF, true)) {
            return;
        }

        String ringtone = sp.getString(ApplicationPreferencesActivity.RINGTONE_PREF, null);

        if (ringtone == null)
            return;

        Uri uri = Uri.parse(ringtone);
        MediaPlayer player = new MediaPlayer();
        player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
        player.setDataSource(context, uri);
        player.setLooping(false);
        player.setVolume(0.25f, 0.25f);
        player.prepare();

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

        audioManager.requestAudioFocus(null, AudioManager.STREAM_NOTIFICATION,
                AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);

        player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                audioManager.abandonAudioFocus(null);
            }
        });

        player.start();
    } catch (IOException ioe) {
        Log.w("MessageNotifier", ioe);
    }
}

From source file:com.securecomcode.text.notifications.MessageNotifier.java

private static void sendInThreadNotification(Context context) {
    try {/*w  ww .  java 2 s .co  m*/
        if (!TextSecurePreferences.isInThreadNotifications(context)) {
            return;
        }

        String ringtone = TextSecurePreferences.getNotificationRingtone(context);

        if (ringtone == null)
            return;

        Uri uri = Uri.parse(ringtone);
        MediaPlayer player = new MediaPlayer();
        player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
        player.setDataSource(context, uri);
        player.setLooping(false);
        player.setVolume(0.25f, 0.25f);
        player.prepare();

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

        audioManager.requestAudioFocus(null, AudioManager.STREAM_NOTIFICATION,
                AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);

        player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                audioManager.abandonAudioFocus(null);
            }
        });

        player.start();
    } catch (IOException ioe) {
        Log.w("MessageNotifier", ioe);
    }
}

From source file:org.thoughtcrime.SMP.notifications.MessageNotifier.java

private static void sendInThreadNotification(Context context, Recipients recipients) {
    try {//from w  ww . j av a 2 s  .  com
        if (!TextSecurePreferences.isInThreadNotifications(context)) {
            return;
        }

        Uri uri = recipients.getRingtone();

        if (uri == null) {
            String ringtone = TextSecurePreferences.getNotificationRingtone(context);

            if (ringtone == null) {
                Log.w(TAG, "ringtone preference was null.");
                return;
            } else {
                uri = Uri.parse(ringtone);
            }
        }

        if (uri == null) {
            Log.w(TAG, "couldn't parse ringtone uri " + TextSecurePreferences.getNotificationRingtone(context));
            return;
        }

        MediaPlayer player = new MediaPlayer();
        player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
        player.setDataSource(context, uri);
        player.setLooping(false);
        player.setVolume(0.25f, 0.25f);
        player.prepare();

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

        audioManager.requestAudioFocus(null, AudioManager.STREAM_NOTIFICATION,
                AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);

        player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                audioManager.abandonAudioFocus(null);
            }
        });

        player.start();
    } catch (IOException ioe) {
        Log.w("MessageNotifier", ioe);
    }
}

From source file:com.mllrsohn.videodialog.VideoDialogPlugin.java

private void playVideo(JSONObject params, final CallbackContext callbackContext) throws JSONException {

    loopVideo = params.optBoolean("loop", true);
    path = params.optString("url");

    uri = Uri.parse(path);/*from www  . java 2s  . c o m*/

    if (path.contains(ASSETS)) {
        try {
            String filepath = path.replace(ASSETS, "");
            String filename = filepath.substring(filepath.lastIndexOf("/") + 1, filepath.length());
            File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + filename);

            if (!fp.exists()) {
                this.copy(filepath, filename);
            }
            uri = Uri.parse("file://" + this.cordova.getActivity().getFilesDir() + "/" + filename);
        } catch (IOException e) {
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION));
        }

    }

    // Create dialog in new thread
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {

            // Set Basic Dialog
            dialog = new Dialog((Context) cordova.getActivity(), android.R.style.Theme_NoTitleBar_Fullscreen);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);

            // Layout View
            RelativeLayout main = new RelativeLayout((Context) cordova.getActivity());
            main.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

            // Video View
            mVideoView = new VideoView((Context) cordova.getActivity());
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            lp.addRule(RelativeLayout.CENTER_IN_PARENT);
            mVideoView.setLayoutParams(lp);

            mVideoView.setVideoPath(uri.toString());
            mVideoView.start();
            main.addView(mVideoView);

            dialog.setContentView(main);
            dialog.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
            dialog.show();

            // Close on touch
            mVideoView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "stopped"));
                    dialog.dismiss();
                    return true;
                }
            });

            // Set Looping
            mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.setLooping(loopVideo);
                }
            });

            // On Completion
            mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mediaplayer) {
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, "Done"));
                    dialog.dismiss();
                }
            });

        }
    });
}

From source file:com.thatkawaiiguy.meleehandbook.activity.VideoInfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (getIntent().hasExtra("bundle") && savedInstanceState == null)
        savedInstanceState = getIntent().getExtras().getBundle("bundle");
    Preferences.applyTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.collapsing_video_layout);
    Slidr.attach(this);

    bp = new BillingProcessor(this, getResources().getString(R.string.licensekey), this);
    bp.loadOwnedPurchasesFromGoogle();//  ww w  .j av a2  s.com

    AdView mAdView = (AdView) findViewById(R.id.adView);
    if (!bp.isPurchased(getResources().getString(R.string.adproductid))) {
        mAdView.loadAd(new AdRequest.Builder().build());
        mAdView.setVisibility(View.VISIBLE);
    } else
        mAdView.setVisibility(View.GONE);

    Bundle mainData = getIntent().getExtras();
    if (mainData == null)
        return;
    optionPicked = mainData.getString("option");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(0x00000000);
        NestedScrollView scroll = (NestedScrollView) findViewById(R.id.video_scrollView);
        scroll.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX,
                    int oldScrollY) {
                if (scrollX < 5)
                    getWindow().setStatusBarColor(0x00000000);
                else
                    getWindow().setStatusBarColor(
                            adjustAlpha(ContextCompat.getColor(getParent(), R.color.theme_accent),
                                    (float) (scrollX + 20) / 10));

            }
        });
    }

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle(optionPicked);

    infoVid = (MutedVideoView) findViewById(R.id.infoVid);
    infoVid.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mp.setVolume(0, 0);
            mp.setLooping(true);
        }
    });

    TextView text = (TextView) findViewById(R.id.infoText);
    text.setText(Html.fromHtml(ArrayHelper.getInfoString(optionPicked, this)));
    text.setTextSize(TypedValue.COMPLEX_UNIT_SP, Integer.parseInt(Preferences.getTextSize(this)));
}

From source file:com.psu.capstonew17.pdxaslapp.CreateCardActivity.java

protected void startVideo() {
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override/*from  ww w  .  j  a  va 2s  .com*/
        public void onPrepared(MediaPlayer mp) {
            mp.setLooping(true);
        }
    });
    video.configurePlayer(videoView);
    videoView.setVisibility(View.VISIBLE);
    bttSubmit.setVisibility(View.VISIBLE);
    videoView.start();
}

From source file:com.android.server.telecom.testapps.TestConnectionService.java

private MediaPlayer createMediaPlayer() {
    // Prepare the media player to play a tone when there is a call.
    MediaPlayer mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.beep_boop);
    mediaPlayer.setLooping(true);
    return mediaPlayer;
}

From source file:com.mikhaellopez.saveinsta.activity.MainActivity.java

@OnClick({ R.id.image_action_play, R.id.video_to_download })
protected void onClickPlayVideo() {
    if (!mVideoToDownload.isPlaying()) {
        Uri uri = Uri.parse(mUrlVideo);/*  w  w w  .  j a va  2s. co m*/
        mVideoToDownload.setVideoURI(uri);
        mVideoToDownload.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.setLooping(true);
            }
        });
        mVideoToDownload.start();
        mVideoToDownload.setVisibility(View.VISIBLE);
    } else {
        mVideoToDownload.setVisibility(View.GONE);
        mVideoToDownload.stopPlayback();
    }
}

From source file:org.schabi.terminightor.NightKillerService.java

private MediaPlayer setupNewMediaPlayer(Alarm alarm) {
    MediaPlayer mediaPlayer = null;
    try {//from   w  w  w  .jav a 2s  .  c  om
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setDataSource(this, Uri.parse(alarm.getAlarmTone()));
        boolean overrideVolume = PreferenceManager.getDefaultSharedPreferences(this)
                .getBoolean(getString(R.string.overrideAlarmVolume), false);
        if (overrideVolume) {
            mediaPlayer.setVolume(1.0f, 1.0f);
        }
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
        mediaPlayer.setLooping(true);
        mediaPlayer.prepare();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mediaPlayer;
}