Android music player controls on lock screen and notifications

2

New! Save questions or answers and organize your favorite content.
Learn more.

Please show me the code that controls the media player (Streaming mp3 from server) from notification and lock screen. I know that's really simple, but i don't know from where to start. I actually doesn't know more about mediaController ,mediaSessionCompat and NotifacationCompat.MediaStyle.

Please refer a code to do say. I just want to play/pause and icon that closes the icon.

Thank your very very much in advance.

asked Feb 21, 2016 at 9:34

Android music player controls on lock screen and notifications

The first thing you need is to register a Media Session and set a callback to receive events from the lock screen.

mSession = new MediaSession(this, "MusicService");
mSession.setCallback(new MediaSessionCallback());
mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);

Create a notification

Notification.Builder notificationBuilder = new Notification.Builder(mService);
notificationBuilder
        .setStyle(new Notification.MediaStyle()
            .setShowActionsInCompactView(new int[]{playPauseButtonPosition})  // show only play/pause in compact view
            .setMediaSession(mSessionToken))
        .setColor(mNotificationColor)
        .setSmallIcon(R.drawable.ic_notification)
        .setVisibility(Notification.VISIBILITY_PUBLIC)
        .setUsesChronometer(true)
        .setContentIntent(createContentIntent(description)) // Create an intent that would open the UI when user clicks the notification
        .setContentTitle(description.getTitle())
        .setContentText(description.getSubtitle())
        .setLargeIcon(art).build()

Add actions using addAction

Notification notification = createNotification();
if (notification != null) {
    mController.registerCallback(mCb);
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_NEXT);
    filter.addAction(ACTION_PAUSE);
    filter.addAction(ACTION_PLAY);
    filter.addAction(ACTION_PREV);
    mService.registerReceiver(this, filter);

    mService.startForeground(NOTIFICATION_ID, notification);
    mStarted = true;
}

Here's a tutorial about Android Music Player Controls on Lock Screen and Notifications

answered Nov 8, 2016 at 15:03

Sapan DiwakarSapan Diwakar

10k5 gold badges32 silver badges43 bronze badges

1

If you’re a music lover, you want to control your tunes even when your phone is locked. Here’s How to Show Music Player on Lock Screen Android!

Sure, you can see the time and your notifications, but where’s the music player? It’s hidden away, that’s where. But not anymore! Today, I’m going to show you how to show the music player on your lock screen.

Ready? Let’s get started!

Introduction

It can be annoying having to unlock your phone every time you want to change a song, especially if you’re using your music player while doing something else. Did you know that you can show the music player on your lock screen, so you can control playback without having to unlock your phone?

What is a lock screen?

A lock screen is a user interface element used by various operating systems, intended to secure access to the device it is installed on. A passcode, pattern, or PIN is usually required to unlock it.

On Android devices, the lock screen is usually the first thing you see when you turn on or wake up your device. It shows your current time, notifications, and more.

The benefits of a music player on your lock screen

A music player on your lock screen can be a great way to control your music without having to unlock your phone. This can be especially useful when you’re driving or doing another activity where you can’t easily access your phone.

There are a few different ways to add a music player to your lock screen, depending on your Android phone. If you have a Samsung Galaxy, you can add the Samsung Music app to your lock screen. Other Android phones may have a built-in music player that can be added to your lock screen, or you can download a third-party music player app from the Google Play Store.

Once you’ve added a music player to your lock screen, you can usually customize how it looks and works. For example, you may be able to choose which controls are displayed, or whether the album artwork is shown. You may also be able to set how long the music player stays on your lock screen before it automatically locks again.

Using a music player on your lock screen can be a great way to control your music without having to unlock your phone every time you want to change a song. It can also help save battery life, as the music player will only stay active on your lock screen for as long as you set it to.

How to Show Music Player on Lock Screen Android?

We all know how convenient it is to be able to control our music from the lock screen on our Android devices. However, did you know that you can also display a music player on your lock screen?

Here’s how:

1. Go to Settings and tap on “Security.”
2. Under the “Screen Security” section, select “Content Settings.”
3. Under the “Content Settings” section, select “Music Player.”
4. Select the “Show on Lock Screen” option.
5. That’s it! Now, whenever you have music playing, you’ll see a music player control on your lock screen.

Android music player controls on lock screen and notifications

How to customize your music player on your lock screen (Android)

It’s easy to change the way your music player looks on your Android phone. You can choose from a variety of different skins and colors, and even add your own personal touch by creating a custom skin.

To change the look of your music player, go to the “Settings” menu and select “Display.” Here you can select the “Theme” option and choose from a number of different skins. If you want to add your own personal touch, you can select the “Customize Skin” option and use an image from your Gallery as your skin.

Once you’ve selected the perfect skin for your music player, go to the “Lock Screen” settings and select “Music controls.” Here you can choose to show or hide the music player on your lock screen. If you choose to show the music player, you can also customize its position on the screen and its transparency.

The pros and cons of having a music player on your lock screen

The music player on your lock screen can be a great way to show off your taste in music, and it can be a great way to control your music without having to unlock your phone. However, there are some potential drawbacks to having a music player on your lock screen. Here are some things to consider:

Pros:

  • -Convenient way to control your music
  • -Can be a great way to show off your taste in music
  • -Can help you stay focused on what you’re doing by eliminating distractions

Cons:

  • -Potential for battery drain if the music player is left on all the time
  • -Can be a security risk if someone gains access to your phone and is able to control the music player
  • -Potential for distraction if you receive notifications while the music player is active

How to hide the music player on your lock screen (Android)

If you’re not a fan of the music player widget taking up space on your lock screen, you can easily disable it. Here’s how:

  • 1.Open the Settings app on your Android device.
  • 2.Tap Sound.
  • 3.Tap the switch next to Show on lock screen to turn it off .

In conclusion

In conclusion, you can display the music player on your lock screen by accessing the settings menu and enabling the music player widget. You can also customize the music player widget to display additional information, such as the song title, artist, and album artwork.

FAQ

Q: How do I show the music player on my lock screen?

  • Lock Screen Widget: Add a music player widget to your lock screen so you can control playback without unlocking your device.
  • Go to your device’s Settings, then tap Lock Screen.
  • Tap Widgets, then tap and hold a widget. Drag it to the desired position on the screen, then release it.
  • Lock Screen Widget: Add a music player widget to your lock screen so you can control playback without unlocking your device.
  • From the Lock Screen widgets screen, tap and hold a widget. Drag it to the desired position on the screen, then release it.

Further reading

If you’re having trouble finding the music player on your lock screen, there are a few things you can do to troubleshoot the issue. First, make sure that the music player is turned on in your phone’s settings. You can usually find this option under “Sounds” or “Security.” If the music player is turned on but still not appearing on your lock screen, try restarting your phone. If that doesn’t work, try resetting your lock screen settings to the default.

How do I get music notifications on my lock screen?

Open your phone's Settings app. Now Playing. Make sure that “Show songs on lock screen” is on.