Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8923777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:13:33+00:00 2026-06-15T07:13:33+00:00

I do have 4 ToggleButtons in my application. All of them are for looping

  • 0

I do have 4 ToggleButtons in my application. All of them are for looping sounds in app. So, it means when I want to click on first ToggleButoon and its state will be on, music starts playing and keep looping untill its state is ON. The same with the rest of ToggleButtons. They might be ON at the same time (all of them) , so I’m planning to have 4 mediaplayers looping.
Here is my peace of code for first TogglleButton, so far no luck even with one….

    public MediaPlayer resourcePlayer;
    Context appContext = getApplicationContext();
    resourcePlayer = MediaPlayer.create(appContext,R.raw.loop1);
    .....
    .....
    public void onClick (View v){
    switch (v.getId()) {
    case R.id.toggleButton1:
    boolean on = ((ToggleButton) v).isChecked();

    if (on) {
    resourcePlayer.start();
    resourcePlayer.setLooping(true)
    }
    else {
    resourcePlayer.stop();
    }

    break;
    }

When I click on ToggleButton nothing happens, only states are changing on phone as i can see, LogCat is also clear. Thanks )
UPD1: Now it’s looping, but when I change state it doesnt stop and keeps looping.
UPD2: resourcePlayer is a public in Main activity
UPD3: I have take out MediaPlayer variables to onCreate menthod so to do not make a duplicates. It plays and stops but only first time after that Logcat is giving error messages

    MediaPlayer start called in state 0
    ....
    ....
    MediaPlayer stop called in state 0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:13:34+00:00Added an answer on June 15, 2026 at 7:13 am

    i think it’s because you keep on creating a new instance of the mediaplayer. so you are always sending the stop command to the newly created mediaplayer object not to the one currently playing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my WPF application to have a ToggleButton that contains an image of
I have a WPF application. In one window there is a combobox..and I want
I want a widget that behaves like a togglebutton and can have its background
In my application, I have a TreeView that allows drag/drop. I have all the
I have a series of ToggleButtons that have a style applied to them. I
I have a list of ToggleButtons being used as the ItemTemplate in a ListBox
Have deployed numerous report parts which reference the same view however one of them
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Well basicly I have a textview and when the application is created it sets
I have a WPF application with ListBox that display list of items. Each item

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.