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 6563595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:52:10+00:00 2026-05-25T13:52:10+00:00

I am working on Android , I am creating a player for audio songs.

  • 0

I am working on Android , I am creating a player for audio songs. I want to play a song only for just 30 seconds. After that, player must be closed. It should be start again, if I press START button again.

This is the code for creating a media player:

    MediaPlayer mediaPlayer = new MediaPlayer();
    public void songPreview(String songURL){

        try{
        mediaPlayer=new MediaPlayer();
        mediaPlayer.setDataSource(songURL);
             mediaPlayer.prepare();
             mediaPlayer.start();

        } catch(Exception ex){
            ex.printStackTrace();
        }
    }

Please suggest me what code should I use to play my song only for 30 seconds after that it will stop, and if I want to play again then I have to press start button.

Note: Please provide me logic to stop media player after 30 second.

Thank you in advance.

  • 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-05-25T13:52:11+00:00Added an answer on May 25, 2026 at 1:52 pm

    use countdownTimer to complete your goal in which you can set countdown timer till 30 second manually. when countdown finish process it will go to finish method and execute finish method code
    ::

        CountDownTimer cntr_aCounter = new CountDownTimer(3000, 1000) {
            public void onTick(long millisUntilFinished) {
    
                mp_xmPlayer2.start();
            }
    
            public void onFinish() {
                //code fire after finish
                   mp_xmPlayer2.stop();
            }
            };cntr_aCounter.start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am working on android. i am creating a login button. i want that
Currently I am working on an Android application that is dynamically creating controls. Everytime
I am working in android. I am creating a mediaPlayer which is running audio
I'm working on creating an android app, and I've found that many classes and
I am working on an Android app that utilizes the Google Maps API MapView,
I have just begun working with the Android SDK and I am having problems
I am working on an Android app that has multiple screens the user will
I have been working on a Android Web Services program that uses a number
I'm creating an Android application (Android 2.3.3) that has a header, a footer and
I have been working on creating an application that sends a string from an

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.