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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:26:56+00:00 2026-06-14T16:26:56+00:00

is there a way to stop mediacontroller from pausing when the screen display turns

  • 0

is there a way to stop mediacontroller from pausing when the screen display turns off either by itself or manually. My app uses the mediacontroller to stream audio files from the internet so I need it to keep playing even if the screen is off.
Any help would be much appreciated.

here is the code for my mediacontroller class:

import android.app.Activity;
import android.content.Context;
import android.view.KeyEvent;
import android.widget.MediaController;

public class WillMediaController extends MediaController {

    public WillMediaController(Context context) {
        super(context);
    }

    @Override
    public void hide() {
        // Do Nothing to show the controller all times

    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event)
    {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK)
        {
            ((Activity) getContext()).finish();

        }else{
            super.dispatchKeyEvent(event);
        }
        if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN ||
                event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
            // don't show the controls for volume adjustment
            return super.dispatchKeyEvent(event);
        }
        return true;


    }
}

Thanks

  • 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-14T16:26:58+00:00Added an answer on June 14, 2026 at 4:26 pm

    I’m not sure if there’s a way to prevent the MediaController from pausing itself when the activity pauses (ie. when the screen goes off), but I do have a couple of ideas:

    First, you could try to disable the screen from timing out in your activity via:

    getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
                         android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    

    However, this probably won’t prevent the user from hitting the lock button and manually turning the screen off and ending the audio playback.

    Second, you could create a Service with a MediaPlayer to play your audio stream in the background and respond to play / pause commands from your app: http://developer.android.com/guide/topics/media/mediaplayer.html#mpandservices

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

Sidebar

Related Questions

Is there any way to stop a WPF Popup from repositioning itself when it
Is there any way to stop a .NET console app from being closed? I've
Is there any way to stop the callout from automatically appearing on an embedded
Is there any way to stop IB in XCode 4 from zooming to try
Is there a way to stop Twisted reactor from automatically swallowing exceptions (eg. NameError)?
Is there a way to stop Microsoft Lync from detecting phone numbers in a
Is there a way to stop other subs from running while in a separate
Is there any way to stop PowerShell from removing console message colors when using
Is there any way to stop the execution of a matlab program from the
Is there a way to stop a HTML entity from being rendered? By that

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.