The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
[W8.1]Problem with app's sound on Windows 10 RRS feed

  • Question

  • Hello,

    I have media player app, today user of my app reported about problem: if he hides app's window, sound becomes lower and after some time system disable sound in my app. I tried it on my Windows 10 copy, do not have problem. User tried to close all other apps. How can we find a reason?



    Thursday, July 30, 2015 6:45 PM

All replies

  • Hello Andev,

    Which project type you are using ?

    Please read the sticky posts, especially the Guide to posting: subject line tags

    Can you provide some sample code so that we can try reproducing this issue on our side?

    I reproduced your issue using UWP HTML app in windows 10. I used HTML video tag.

    <body class="win-type-body">
        <video controls loop>
            <source src=http://techslides.com/demos/sample-videos/small.webm type=video/webm>
            <source src=http://techslides.com/demos/sample-videos/small.ogv type=video/ogg>
            <source src=http://techslides.com/demos/sample-videos/small.mp4 type=video/mp4>
            <source src=http://techslides.com/demos/sample-videos/small.3gp type=video/3gp>
        </video>
    
    </body>

    I tried it with both full screen and without full screen and same behavior each time once minimized it stopped playing(I think by default behaviour). Can you please find the state of the app when he hide's the app's window. Please provide some more info / code on how I can reproduce this issue.

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Friday, July 31, 2015 6:25 AM
  • Hello,

    it is Windows Store app, package for Windows 8.1. I use simple MediaElement class to play radio streams in my app with background playing capability. It is C#/XAML project.

    Friday, July 31, 2015 8:10 AM
  • Please help, many Win10 users complains about it. Why does it work on Windows 8.1 and sometimes doesn't work on Windows 10?
    Monday, August 3, 2015 1:46 PM
  • Hello Andev,

    So I fixed this issue on my windows 10 machine after adding background audio capabilities and systemmediatransportcontrols.

    Please see: How to use the system media transport controls (XAML)

    you also need to set background audio task in app manifest and also need to set audiocategory to BackgroundCapableMedia media.

    Please see: How to play audio in the background (XAML)

    Here is a working code that I tested.

    <?xml version="1.0" encoding="utf-8"?>
    <Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest">
      <Identity Name="d9cc1650-adf7-44a7-a335-ffefb7a91684" Publisher="CN=v-krpare" Version="1.0.0.0" />
      <Properties>
        <DisplayName>BackgroundMedia</DisplayName>
        <PublisherDisplayName>v-krpare</PublisherDisplayName>
        <Logo>Assets\StoreLogo.png</Logo>
      </Properties>
      <Prerequisites>
        <OSMinVersion>6.3.0</OSMinVersion>
        <OSMaxVersionTested>6.3.0</OSMaxVersionTested>
      </Prerequisites>
      <Resources>
        <Resource Language="x-generate" />
      </Resources>
      <Applications>
        <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="BackgroundMedia.App">
          <m2:VisualElements DisplayName="BackgroundMedia" Square150x150Logo="Assets\Logo.png" Square30x30Logo="Assets\SmallLogo.png" Description="BackgroundMedia" ForegroundText="light" BackgroundColor="#464646">
            <m2:SplashScreen Image="Assets\SplashScreen.png" />
          </m2:VisualElements>
          <Extensions>
            <Extension Category="windows.backgroundTasks" EntryPoint="BackgroundMedia">
              <BackgroundTasks>
                <Task Type="audio" />
              </BackgroundTasks>
            </Extension>
          </Extensions>
        </Application>
      </Applications>
      <Capabilities>
        <Capability Name="internetClient" />
        <Capability Name="musicLibrary" />
        <Capability Name="videosLibrary" />
      </Capabilities>
    </Package>

    You can set the background audio task in app manifest using Declaration > Add Declaration > Background Tasks > Set Supported type to audio and entry point to your app name.

    XAML

    <Page
        x:Class="BackgroundMedia.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:BackgroundMedia"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Grid VerticalAlignment="Top">
            <Button Content="Select a media file" Margin="10" Click="Button_Click"/>
            </Grid>
            <Grid>
            <MediaElement x:Name="player" AudioCategory="BackgroundCapableMedia" CurrentStateChanged="player_CurrentStateChanged" IsLooping="True" AreTransportControlsEnabled="True" AutoPlay="True" Width="Auto" Height="300"></MediaElement>
            </Grid>
        </Grid>
    </Page>
    

    Code Behind

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.Media;
    using Windows.Storage;
    using Windows.Storage.Pickers;
    using Windows.Storage.Streams;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    
    // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
    
    namespace BackgroundMedia
    {
      /// <summary>
      /// An empty page that can be used on its own or navigated to within a Frame.
      /// </summary>
      public sealed partial class MainPage : Page
      {
        SystemMediaTransportControls systemMediaControls = null;
        
        public MainPage()
        {
          this.InitializeComponent();
          // Handle events from system transport contrtols when playing background-capable media
          systemMediaControls = SystemMediaTransportControls.GetForCurrentView();
          systemMediaControls.ButtonPressed += SystemMediaControls_ButtonPressed;
          systemMediaControls.IsPlayEnabled = true;
          systemMediaControls.IsPauseEnabled = true;
          systemMediaControls.IsStopEnabled = true;
        }
    
        private async void SystemMediaControls_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs e)
        {
          switch (e.Button)
          {
            case SystemMediaTransportControlsButton.Play:
              await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
              {
                player.Play();
              });
              break;
    
            case SystemMediaTransportControlsButton.Pause:
              await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
              {
                player.Pause();
              });
              break;
    
            case SystemMediaTransportControlsButton.S          await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
              {
                player.Stop();
              });
              break;
    
            default:
              break;
          }
        }
    
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
          FileOpenPicker fileOpenPicker = new FileOpenPicker();
    
          // Filter to include a sample subset of file types
          fileOpenPicker.FileTypeFilter.Add(".wmv");
          fileOpenPicker.FileTypeFilter.Add(".mp4");
          fileOpenPicker.FileTypeFilter.Add(".mp3");
          fileOpenPicker.FileTypeFilter.Add(".wma");
          fileOpenPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
    
          StorageFile file = await fileOpenPicker.PickSingleFileAsync();
    
          // Ensure a file was selected
          if (file != null)
          {
            MediaPlaybackType mediaPlaybackType;
            if ((file.FileType == ".mp4") || (file.FileType == ".wmv"))
            {
              mediaPlaybackType = MediaPlaybackType.Video;
            }
            else
            {
              mediaPlaybackType = MediaPlaybackType.Music;
            }
    
            // Inform the system transport controls of the media information
            if (!(await systemMediaControls.DisplayUpdater.CopyFromFileAsync(mediaPlaybackType, file)))
            {
              //  Problem extracting metadata- just clear everything
              systemMediaControls.DisplayUpdater.ClearAll();
            }
            systemMediaControls.DisplayUpdater.Update();
    
            IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
    
            // Set the selected file as the MediaElement's source
            player.SetSource(stream, file.ContentType);
          }
        }
    
        private void player_CurrentStateChanged(object sender, RoutedEventArgs e)
        {
          SystemMediaTransportControls systemMediaControls = SystemMediaTransportControls.GetForCurrentView();
          switch (player.CurrentState)
          {
            default:
            case MediaElementState.Closed:
              systemMediaControls.PlaybackStatus = MediaPlaybackStatus.Closed;
              break;
    
            case MediaElementState.Opening:
              systemMediaControls.PlaybackStatus = MediaPlaybackStatus.Changing;
              break;
    
            case MediaElementState.Buffering:
            case MediaElementState.Playing:
              systemMediaControls.PlaybackStatus = MediaPlaybackStatus.Playing;
              break;
    
            case MediaElementState.Paused:
              systemMediaControls.PlaybackStatus = MediaPlaybackStatus.Paused;
              break;
    
            case MediaElementState.Stopped:
              systemMediaControls.PlaybackStatus = MediaPlaybackStatus.Stopped;
              break;
          }
        }
      }
    }
    

    With Regards,

    Krunal Parekh



    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Proposed as answer by Krunal Parekh Friday, August 7, 2015 2:23 AM
    Friday, August 7, 2015 2:22 AM
  • Thanks, but I already added background playing capability since Windows 8.0. I and my users do not have a problem with sound in background if they use app in the Windows 8/8.1. Problem with playing sound is in the Windows 10 and only for some users, not for all, for example on my copy of Windows 10 my app plays sound in the background normally. I will compare your code with my, may be I missed something.
    Friday, August 7, 2015 6:34 AM
  • any news? many users complained, but not all, one user reported what problem was solved on his computer without changing anything.
    Monday, August 17, 2015 8:49 PM
  • any news? many users complained, but not all, one user reported what problem was solved on his computer without changing anything.

    Hello Andev,

    Since I am not able to reproduce the issue with the working code on windows 10 I am not sure how to assist you more on this matter without some actual information regarding the problem on your client's machines. Did you compare your code with the one that I provided? Were you able to find if you missed anything? Although might not be related but could you check this settings on your client machines.

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, August 18, 2015 1:58 AM
  • I am having the exact same problem. My app works very well on Windows 8.x. But on Windows 10, more and more users complain that the app gets muted when minimized, or that the app stops playback on track end, when it is minimized. I cannot reproduce it myself. On my devices, background playback works well even on Windows 10.

    But I see that Windows 10 also has other problems when the app is minimized: For example if I use the transport controls that appear when I hover the app, or the controls that appear when pressing the volume button: When the app is minimized and I pause the app, the controls will still show it as playing. They do not update although I send updates of course. So I can pause playback when minimized, but then I cannot resume it anymore because there is no play button. I have to open the app once, only then the controls do update. This works well on Windows 8.x when the app is minimized, but it is broken on Windows 10. I do send the updates to the transport controls, as can be seen when the app is once opened. But it looks like the app's message loop is blocked somehow, even though it is not yet suspended. Only when it is re-opened once, the update to the playback controls comes through. I think that the same issue might be causing the track end problem: The track ends and my app's message loop is stopped instantly, so it cannot start playback of the next track and hangs, until opened again.

    Wednesday, August 19, 2015 7:12 PM
  • any news? many users complained, but not all, one user reported what problem was solved on his computer without changing anything.

    Hello Andev,

    Since I am not able to reproduce the issue with the working code on windows 10 I am not sure how to assist you more on this matter without some actual information regarding the problem on your client's machines. Did you compare your code with the one that I provided? Were you able to find if you missed anything? Although might not be related but could you check this settings on your client machines.

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    asked one user, this solution did not help, I compared code, all the same.
     One user reported what this problem occurred not in all cases, 1 of 30.
    • Edited by Andev Saturday, August 22, 2015 10:20 AM
    Saturday, August 22, 2015 10:16 AM
  • please solve problem asap, many Win10 users complain and only Win10 users, on Win8 all works fine.
    Sunday, August 30, 2015 2:02 PM
  • We have reproduced the reported SMTC problem and are investigating the root cause. This is what we are seeing. Let us know if this is the same or different than what you are observing.

    1. Start playing music in the background
    2. Minimize the app
    3. Music continues to play in the background
    4. Bring up the SMTC with the system volume buttons
    5. Click Pause and music pauses
    6. Click Play and music continues playing but in a muted state
    7. Clicking Next track has the same effect of muting audio
    8. Audio is restored by bringing the app to the foreground
    Tuesday, September 1, 2015 7:59 PM
  • Hello, playing was stopped because I implemented code below, it was good for Windows 8 but because of bug in Windows I decided to comment code, so now playing is not stopped when sound is muted. 2 years ago my app failed certification because player did not stop playing radio stream when sound is not audible for user, so I added code.

            async void systemControls_PropertyChanged(SystemMediaTransportControls sender, SystemMediaTransportControlsPropertyChangedEventArgs args)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                //if (systemControls.SoundLevel == SoundLevel.Muted)
                //    Player.Pause();
                });
            }

    Wednesday, September 2, 2015 6:47 PM
  • Interesting finding! Why does Windows mute the app just because it gets minimized? I guess that your users aren't doing a skype call just then...

    Are you sure that the problem is really gone now with this code commented? I would assume that the volume will still go down, just that your playback will now continue (but silently!).

    Wednesday, September 2, 2015 8:13 PM
  • Interesting finding! Why does Windows mute the app just because it gets minimized? I guess that your users aren't doing a skype call just then...

    Are you sure that the problem is really gone now with this code commented? I would assume that the volume will still go down, just that your playback will now continue (but silently!).

    I think so too, but I can't reproduce problem.
    Thursday, September 3, 2015 5:55 AM
  • Today this problem was reproduced on my copy of Windows 10 in my app, playing was stopped after app gets minimized, reboot solved problem.
    Sunday, September 27, 2015 1:10 PM
  • this problem is reproduced on Windows 10 November Update with all updates, when do you plan to fix it?
    Tuesday, December 22, 2015 3:33 PM
  • If this still reproduces with WIP Build 11082 please let me know.

    https://blogs.windows.com/windowsexperience/2015/12/16/announcing-windows-10-insider-preview-build-11082/

    There are a couple different issues reported in this thread so if you are still experiencing a problem with that build, please let me know what you are seeing, what you expect to see, and the steps for us to reproduce. Thank you.


    Tuesday, December 22, 2015 6:36 PM