I am using MedialPlayer control to play sound effects in my app as explained here. Sounds are short sound effects that play "in the background" when something happens in the app, user should not see any sort of media playback control.
Code is fairly straight forward, looks something like this:
MediaPlayer mPlayer = new MediaPlayer();
mPlayer.Source = MediaSource.CreateFromUri(pathUri);
mPlayer.Play();
This works well, except, when user presses volume control button on the keyboard, a mini media player control appears next to volume control and the user can press play button to play the last sound again (see picture). I want to hide this. User should not see this or be able to replay sounds.
Solutions offered in question 14578867 do not work. Properties mentioned in the answers do not exist (e.g. IsPlayPauseVisible, uImode, IsInteractive). I tried using similar properties from SystemMediaTransportControls but it makes no difference. I think these are meant for the control that appears in the app (which I do not have), not for the "OS media control" that I want to hide.
mPlayer.SystemMediaTransportControls.IsEnabled = false;
mPlayer.SystemMediaTransportControls.IsPlayEnabled = false;
How can I disable/hide this?
Here is a step-by-step guide to replicate the issue:
- Create a new Windows Universal Visual C# Blank App
- Add a button to MainPage.xaml and mp3 file to assets
- Paste below code to MainPage.cs
- Run the app, click button
- On the keyboard press volume up button
- Observe the "media control" with play button next to volume control (see image above).
Pressing play button plays the sound again. If you are quick you can also pause the playback. SystemMediaTransportControls properties make no difference.
using Windows.Media.Core;
using Windows.Media.Playback;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
namespace App2
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Button_Tapped(object sender, TappedRoutedEventArgs e)
{
MediaPlayer mPlayer = new MediaPlayer();
mPlayer.Source = MediaSource.CreateFromUri(new System.Uri("ms-appx:///Assets/clap.mp3"));
mPlayer.SystemMediaTransportControls.IsPlayEnabled = false;
mPlayer.SystemMediaTransportControls.IsEnabled = false;
mPlayer.Play();
}
}
}