Wrong volume control stream for CastPlayer in a Service











up vote
0
down vote

favorite












I'm using the ExoPlayer Google Cast extension v2.8.4. When playing content using the CastPlayer, the device's physical volume buttons should control the receiver device's volume. This behaves as expected when the CastPlayer is contained within an Activity. However, when the CastPlayer is contained within a Service (such as a MediaBrowserServiceCompat) the physical volume buttons change the sender device's media volume.



I've created 2 sample projects demonstrating the issue:





  • CastVolumeControlTest shows the proper volume control stream behavior while casting.


  • CastVolumeControlServiceTest shows the incorrect volume control stream behavior while casting.


As seen in the image below, the cast device volume does appear in the full volume controls view, but the phone's media volume is the active control stream when the CastPlayer is in a service.



Is there a way to set the proper volume control stream in the Service implementation?



enter image description here










share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm using the ExoPlayer Google Cast extension v2.8.4. When playing content using the CastPlayer, the device's physical volume buttons should control the receiver device's volume. This behaves as expected when the CastPlayer is contained within an Activity. However, when the CastPlayer is contained within a Service (such as a MediaBrowserServiceCompat) the physical volume buttons change the sender device's media volume.



    I've created 2 sample projects demonstrating the issue:





    • CastVolumeControlTest shows the proper volume control stream behavior while casting.


    • CastVolumeControlServiceTest shows the incorrect volume control stream behavior while casting.


    As seen in the image below, the cast device volume does appear in the full volume controls view, but the phone's media volume is the active control stream when the CastPlayer is in a service.



    Is there a way to set the proper volume control stream in the Service implementation?



    enter image description here










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm using the ExoPlayer Google Cast extension v2.8.4. When playing content using the CastPlayer, the device's physical volume buttons should control the receiver device's volume. This behaves as expected when the CastPlayer is contained within an Activity. However, when the CastPlayer is contained within a Service (such as a MediaBrowserServiceCompat) the physical volume buttons change the sender device's media volume.



      I've created 2 sample projects demonstrating the issue:





      • CastVolumeControlTest shows the proper volume control stream behavior while casting.


      • CastVolumeControlServiceTest shows the incorrect volume control stream behavior while casting.


      As seen in the image below, the cast device volume does appear in the full volume controls view, but the phone's media volume is the active control stream when the CastPlayer is in a service.



      Is there a way to set the proper volume control stream in the Service implementation?



      enter image description here










      share|improve this question













      I'm using the ExoPlayer Google Cast extension v2.8.4. When playing content using the CastPlayer, the device's physical volume buttons should control the receiver device's volume. This behaves as expected when the CastPlayer is contained within an Activity. However, when the CastPlayer is contained within a Service (such as a MediaBrowserServiceCompat) the physical volume buttons change the sender device's media volume.



      I've created 2 sample projects demonstrating the issue:





      • CastVolumeControlTest shows the proper volume control stream behavior while casting.


      • CastVolumeControlServiceTest shows the incorrect volume control stream behavior while casting.


      As seen in the image below, the cast device volume does appear in the full volume controls view, but the phone's media volume is the active control stream when the CastPlayer is in a service.



      Is there a way to set the proper volume control stream in the Service implementation?



      enter image description here







      android google-cast exoplayer android-exoplayer google-cast-sdk






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 17:10









      deRonbrown

      551514




      551514
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          I've determined the issue, and the cause is not due to a bug in ExoPlayer or the Cast extension. This commit in the CastVolumeControlServiceTest fixes the issue.



          After debugging and looking through the device's logs, I discovered that the volume key events were directed to the active MediaSession. By setting the MediaSession to inactive, the volume control stream will control the receiver device, so the solution is the toggle MediaSession to active/inactive depending on which Player is current.



          This didn't seem intuitive, but it works.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194439%2fwrong-volume-control-stream-for-castplayer-in-a-service%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            I've determined the issue, and the cause is not due to a bug in ExoPlayer or the Cast extension. This commit in the CastVolumeControlServiceTest fixes the issue.



            After debugging and looking through the device's logs, I discovered that the volume key events were directed to the active MediaSession. By setting the MediaSession to inactive, the volume control stream will control the receiver device, so the solution is the toggle MediaSession to active/inactive depending on which Player is current.



            This didn't seem intuitive, but it works.






            share|improve this answer

























              up vote
              1
              down vote













              I've determined the issue, and the cause is not due to a bug in ExoPlayer or the Cast extension. This commit in the CastVolumeControlServiceTest fixes the issue.



              After debugging and looking through the device's logs, I discovered that the volume key events were directed to the active MediaSession. By setting the MediaSession to inactive, the volume control stream will control the receiver device, so the solution is the toggle MediaSession to active/inactive depending on which Player is current.



              This didn't seem intuitive, but it works.






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                I've determined the issue, and the cause is not due to a bug in ExoPlayer or the Cast extension. This commit in the CastVolumeControlServiceTest fixes the issue.



                After debugging and looking through the device's logs, I discovered that the volume key events were directed to the active MediaSession. By setting the MediaSession to inactive, the volume control stream will control the receiver device, so the solution is the toggle MediaSession to active/inactive depending on which Player is current.



                This didn't seem intuitive, but it works.






                share|improve this answer












                I've determined the issue, and the cause is not due to a bug in ExoPlayer or the Cast extension. This commit in the CastVolumeControlServiceTest fixes the issue.



                After debugging and looking through the device's logs, I discovered that the volume key events were directed to the active MediaSession. By setting the MediaSession to inactive, the volume control stream will control the receiver device, so the solution is the toggle MediaSession to active/inactive depending on which Player is current.



                This didn't seem intuitive, but it works.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 16:13









                deRonbrown

                551514




                551514






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194439%2fwrong-volume-control-stream-for-castplayer-in-a-service%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown