[Xamarin Blog] Lock Screen Music Controls in Xamarin.Android

JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai
edited January 2014 in Xamarin.Android

Just posted: Lock Screen Music Controls in Xamarin.Android on the Xamarin Blog.

Read the full article to learn how to up enhance your music streaming Xamarin.Android app by adding lock screen transport controls and artwork.

Use this thread to discuss or ask questions.

Posts

  • PerCramerPerCramer NLUniversity ✭✭

    Hi,

    i tried it, but nothing shows up in my lockscreen. Should i change some system settings? The device is running Android 4.2.1

    Regards,

    Per

  • ChristopherDrososChristopherDrosos GRMember ✭✭
    edited August 2014

    im wondering if i can add custom buttons on the lock screen such as play audio file from next or previous audio category. is this possible?
    also you are making some broadcast recievers in the folder recievers and those recievers are not mentioned on mainactivity or in the service. android is going to use them either way?

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    Not as far as I know. Each phone can theme it differently.

  • carleslscarlesls ESMember

    ups the blog link is broken.
    Thank you anyway.

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    @carlesls which link?

  • carleslscarlesls ESMember

    Is it possible to use the lock screen controls to do other things like playing a very simple spaceship game while listening to music...
    Is it possible to customize the locked screen with a layout?
    Is it intelligent to initialize or update the lock screen from the service that initializes and updates the notification bar?
    Thank you.

  • carleslscarlesls ESMember
    edited December 2014

    What about a ProgressBar or even a SeekBar inside the lockscreen... is it possible??
    Or even something unrelated to a player or music... then should I use the audiomanager??
    How do you do that?
    Thanks again.

  • ChristopherDrososChristopherDrosos GRMember ✭✭
    edited December 2014

    from my understanding you can only change and use the actions from the lockscreen (playnext, forward, playpause, stop etc) and also you can change name,artist, album image
    you cannot modify the interface.

    James, it would be nice an update for the lollipop because Lock screen widgets are gone and now we have to use notification shade controls

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    I will be updating my Nexus 7 device to lollipop when I get back home in a few weeks and will take a look at it.

    And you are correct about what you can and can not put on the lock screen. The RemoteControlClient handles this: http://developer.android.com/reference/android/media/RemoteControlClient.html

  • sizeaksizeak USMember

    Sorry to necro the thread but I think the example is missing a call to AudioManager.RequestAudioFocus. Until I added this I could not get the lock screen to show the controls.

  • AlexvanMeertenAlexvanMeerten NLMember ✭✭

    Hi @JamesMontemagno
    Did you manage to get the Music Controls working on the lock screen for Lollipop?

  • Martijn00Martijn00 NLInsider, University ✭✭✭

    @AlexvanMeerten Take a look at: https://github.com/jamesmontemagno/AndroidStreamingAudio/blob/master/Part 3 - MediaSessionCompat/Services/MediaPlayerService.cs

    That works with the new media style notifications and has support for lock screen controls!

  • AlexvanMeertenAlexvanMeerten NLMember ✭✭

    @Martijn00: that looks promising, thnx!

  • @JamesMontemagno @Martijn00 as RemoteControlClient is deprecated as well as RegisterMediaButtonEventReceiver on AudioManager - could you please give us an example how to do it without these two?

    Cheers

  • Martijn00Martijn00 NLInsider, University ✭✭✭

    @JakubHolovsky The example is using MediaSessionCompat, but for devices with lower then Android lolipop you still need RemoteControlClient.

  • @Martijn00 do you think in that case it would be better to check

    if (Build.VERSION.SdkInt <= BuildVersionCodes.Kitkat)
    // instantiate RemoteControlClient
    // otherwise don't

    I am a little bit confused how they are all mixed together when it seems that the are aimed at two different series of the Android APIs.

  • @JakubHolovsky said:
    @Martijn00 do you think in that case it would be better to check

    if (Build.VERSION.SdkInt <= BuildVersionCodes.Kitkat)
    // instantiate RemoteControlClient
    // otherwise don't

    I am a little bit confused how they are all mixed together when it seems that the are aimed at two different series of the Android APIs.

    Actually, I was confused by mistake, the examples were perfectly clear :)

  • ebetzlerebetzler USMember ✭✭

    I'm using @JamesMontemagno demo "BackgroundStreamingAudio" as-is.
    My lock screen controls do not do anything on API < 21.

    =21 is good, just old version doesn't work.

    Notification controls work fine for both. Just the lock screen is not working as expected.
    Anyone else notice this?

  • ebetzlerebetzler USMember ✭✭

    @ebetzler said:
    I'm using @JamesMontemagno demo "BackgroundStreamingAudio" as-is.
    My lock screen controls do not do anything on API < 21.

    =21 is good, just old version doesn't work.

    Notification controls work fine for both. Just the lock screen is not working as expected.
    Anyone else notice this?

    I should add, I am referring to the most latest example on GitHub, "Part3: MediaSessionCompat"

  • ThetSweThetSwe SGMember

    Part3: MediaSessionCompat
    Working fine on the notification bar but doesn't show on lock screen. Do I need any special permission for this?
    Running on Android 6.0!

  • KrishnaChirravuriKrishnaChirravuri USMember ✭✭

    @Martijn00 MediaSessionCompat shows on lock screen but controls are not working work, whenever I press the pause button I get the below message in output
    [0:] mvx:Warning: 59.54 OnViewNewIntent called - but this is not fully handled within MvvmCross currently. Check https://github.com/slodge/MvvmCross/pull/294 for more info

    Am I missing anything ?

Sign In or Register to comment.