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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:25:55+00:00 2026-05-27T07:25:55+00:00

I have build an app that use mp3-files. In the first version the files

  • 0

I have build an app that use mp3-files. In the first version the files was included in the apk-file. I now are working on a version that have the mp3-files in an URL-resource.
I have adjust the code and almost everything works fine.
The problem is that the buttons for stop, pause and play now not is working.
This is the code that start the streaming (works fine):

private void playAudio(String media) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    try {
        mediaPlayer.setDataSource(media);
        mediaPlayer.prepare(); // might take long! (for buffering, etc)
        mediaPlayer.start();

    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
    }
    mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
        public void onCompletion(MediaPlayer arg0) {
            finish();
        }
    });

}

And this is the functions I use for stopping etc. Worked fine with local file (raw-resources) But now it is not working:

    @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Intent intent = new Intent(SpelaSaga.this, VisaIngressSaga.class);
        Bundle bundle = new Bundle();
        bundle.putString("Titel", titel);
        bundle.putInt("Position", position);
        intent.putExtras(bundle);
        SpelaSaga.this.startActivity(intent);
        finish();
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

private OnClickListener button_1Listener = new OnClickListener() {
    @Override
    public void onClick(View v) {
        mediaPlayer.stop();
        Intent intent = new Intent(SpelaSaga.this, VisaIngressSaga.class);
        Bundle bundle = new Bundle();
        bundle.putString("Titel", titel);
        bundle.putInt("Position", position);
        intent.putExtras(bundle);
        SpelaSaga.this.startActivity(intent);
        finish();

    }
};

private OnClickListener button_2Listener = new OnClickListener() {
    @Override
    public void onClick(View v) {
        mediaPlayer.pause();

    }
};

I have looked around and have only find old versions of streaming tutorials that needs much more coding. Hope someone out there have a good idea of how to control the streaming.

  • 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-27T07:25:56+00:00Added an answer on May 27, 2026 at 7:25 am

    I created very similar app, my code looks like this:

    public void startSound(final String URL) {
        bt.setText("STOP");
        new Thread() {
            public void run() {
                try {
                    Uri uri = Uri.parse(URL);
    
                    mp = MediaPlayer.create(PlaySound.this, uri);
                    mp.start();
                    mp.setOnCompletionListener(new OnCompletionListener() {
                        @Override
                        public void onCompletion(MediaPlayer arg0) {
                            bt.setEnabled(true);
                            bt.setText("SŁUCHAJ");
                        }
                    });
                } catch (Exception e) {
    
                }
                myProgressDialog.dismiss();
            }
        }.start();
    }
    

    when I press back button:

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            try {
                mp.stop();
            } catch (Exception e) {
    
            }
        }
        return super.onKeyDown(keyCode, event);
    }
    

    i hope, that this answer help You 😉

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

Sidebar

Related Questions

We have multiple config files (app.DEV.config, app.TEST.config, etc) and a pre-build event that copies
I have an app that my users use to build objects. For example, they
I have a Python app that works fine. Now I use py2exe to create
I have a nice working iphone app that works with core data. I use
I have a Flex App that allows you to dynamically build an animation. It
I have an idea for an app that I would like to build which
I have to build small (for now) admin app in Silverlight2, and would like
I have the localized strings file that is used in the Iphone app that
Lets say I wanted to build an app that will pull url links from
I'd like to use python to build an app that is similar to zeroMQ

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.