<Button
x:Name="PlayButton"
Click="PlayButton_Click"
Style="{StaticResource MediaControlButtonStyle}">
<Button.Content>
<FontIcon
x:Name="PlayButtonIcon"
FontSize="30"
Glyph="" />
</Button.Content>
<Button.KeyboardAccelerators>
<KeyboardAccelerator Key="F3" />
</Button.KeyboardAccelerators>
</Button>
I want to use F3 to play/pause the music in my UWP app. However, simply pressing F3 doesn't work on my Surface Book 2. I need to press both FN and F3 to make it work. What should I do so that I only need to press F3? The Microsoft builtin UWP app Groove Music plays and pauses functionally with pressing F3 only.
Another question is that how can I still use keyboard accelerator when the window of UWP app is minimized? The keyboard control of Groove still works with its window minimized.
It seems the behavior -- need to press FN or not,is related to the device that installed the app.When I run in PC,I only need to press F3,but it requires FN on the surface.If you still wants to change it,I have a workaround below,you can register Accelerator events on the page (e.g. MainPage).
public MainPage()
{
this.InitializeComponent();
Window.Current.Dispatcher.AcceleratorKeyActivated += AccelertorKeyActivedHandle;
}
private void AccelertorKeyActivedHandle(CoreDispatcher sender, AcceleratorKeyEventArgs args)
{
if (args.EventType.ToString().Contains("Down"))
{
if (args.VirtualKey == Windows.System.VirtualKey.F3)
{
// do something you want
}
}
}
When the window of UWP app is minimized,the current window has no focus, so the set shortcuts will not be responded.But the system has its default shortcuts(e.g. Fn + F11) can play or pause media.If you want to respond the system shortcuts,you need to allow backgroundMediaPlayback.You can try the official demo, which can also be controlled by the media button that comes with the keyboard.
Update:
According to the official sample,if you want to use MediaElement to play,you should set MediaPlay and MediaPlaybackList to bind the playback list.In this case, it seems can be controlled by the system default shortcut keys.What actually works is MediaPlayer.For more detailed information, you still need to read the official demo.
XAML:
<MediaElement Name="mediaPlayerElement"
AreTransportControlsEnabled="True"
Stretch="UniformToFill" Height="100" Width="400">
Code-behind:
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/xxx"));
// Create a configurable playback item backed by the media source
var playbackItem = new MediaPlaybackItem(source);
MediaPlayer player = new MediaPlayer();
MediaPlaybackList lists = new MediaPlaybackList();
lists.Items.Add(playbackItem);
player.Source = lists;
}
Related
I'm developing an app and I'd like when the user is in Tablet Mode and switches from one app to other to show a black screen when you press "alt + tab" and the opened apps are being shown. I'd like instead of showing the "myTrip" screenshot of the app to show a black screen.
I know for WPF we had ShowInTaskbar = false but nothing like that in Windows 10 Universal App Platform.
I tried so far:
Window.Current.CoreWindow.VisibilityChanged += CoreWindow_VisibilityChanged;
private void Current_VisibilityChanged(object sender, VisibilityChangedEventArgs e)
{
var parentGrid = RootPanel();
parentGrid.Visibility = e.Visible ? Visibility.Visible : Visibility.Collapsed;
}
But the snapshot image of the app is taken before those events are being called. Any idea on how to do it?
Regards.
I don't get why exactly you want to do this, but here it goes.
You'll need to handle the Activated event of the current thread, and than place a control over your content. See the example bellow.
First, the XAML:
<Canvas Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >
<Canvas x:Name="contetProtector" Canvas.ZIndex="10" Background="Black" Width="1014" Height="758" Visibility="Collapsed"/>
<TextBlock Text="My precious content" FontSize="50" Canvas.Top="50" Canvas.Left="50"/>
<TextBlock Text="Nobody should see it" FontSize="50" Canvas.Top="100" Canvas.Left="50"/>
</Canvas>
Then, the codebehind of the page:
public MainPage()
{
this.InitializeComponent();
CoreWindow.GetForCurrentThread().Activated += CoreWindowOnActivated;
}
private void CoreWindowOnActivated(CoreWindow sender, WindowActivatedEventArgs args)
{
if(args.WindowActivationState == CoreWindowActivationState.Deactivated)
this.contetProtector.Visibility = Visibility.Visible;
else
this.contetProtector.Visibility = Visibility.Collapsed;
}
Here you can see the unprotected/active screen, and here the protected one.
Hope it helps.
I am making a windows phone app, I want to run the video whenever the button is pressed. I am using mediaelement to run it, here is the code:
XAML:
<MediaElement x:Name="myMediaElement"
Margin="0,40,0,40"
Height="400"
Width="240" />
<Button x:Name="playVideoButton"
Height="80"
Width="200"
Content="Play Video"
Click="playVideoButton_Click"/>
C#:
private void playVideoButton_Click(object sender, RoutedEventArgs e)
{
myMediaElement.Source = new Uri("ms-appx:///Assets/Video.mp4", UriKind.RelativeOrAbsolute);
myMediaElement.Play();
}
this is the basic code that i am trying to run the video so if this one runs i'll add pause feature as well, but unfortunately its not running.
Please help and thanks in Advance!
Shahrukh
you can refer a Nokia Developer Sample about Video Playback with MediaElement in Windows Phone or you can Use Media Player launcher instead. here is a MSDN Documentation about it. How to use the Media Player launcher for Windows Phone 8
When performing an async function to either get local data, access a file, or call an API, how do you trigger the loading animation during this, possibly, long routine?
Here's an example:
<Button onClick="Button_Click" />
public async void Button_Click(object sender, RoutedEventArgs e)
{
var myData = await MyDataManager.GetMyData();
await new MessageDiaglog("Data Loaded!").ShowAsync();
}
Since it's a universal store app, I assume it should work the same in both windows 8.1 and windows phone 8.1.
UPDATE FROM SOLUTION
Per igrali answer, I updated my code for future reference:
<ProgressBar x:Name="LoadingBar" Visibility="Collapsed" IsEnabled="False" IsIndeterminate="true" Height="4" HorizontalAlignment="Stretch"/>
<Button onClick="Button_Click" />
public async void Button_Click(object sender, RoutedEventArgs e)
{
LoadingBar.IsEnabled = true;
LoadingBar.Visibility = Visibility.Visible;
var myData = await MyDataManager.GetMyData();
await new MessageDiaglog("Data Loaded!").ShowAsync();
LoadingBar.IsEnabled = false;
LoadingBar.Visibility = Visibility.Collapsed;
}
This code will work on both the Phone and Tablet.
There's a pretty standardized way of doing this on Windows Phone. Since it's a Universal app, probably the best choice is to show a progress ring.
You add it in XAML
<ProgressRing IsActive="True"/>
You can show it either explicitly in code behind when button is clicked, or use a bool property in a viewmodel (if you use MVVM) and a ValueConverter to show it or hide it by simply changing one property from true to false and vice versa.
I also suggest reading the official documentation about progress controls and I'll end this answer with a tip from ProgressRing documentation that can be found here
Set the IsActive property to turn the ProgressRing on or off. If
IsActive is false, the ProgressRing is not shown, but space is
reserved for it in the UI layout. To not reserve space for the
ProgressRing, set it's Visibility property to Collapsed.
Tip When the ProgressRing is active, the progress animation continues
even if its not visible on the screen, such as when it's Visibility is
Collapsed. This can keep the UI thread awake, use resources, and
impair app performance. When the ProgressRing is not visible, you
should disable the animation by setting IsActive to false.
I am working on windows store app (using xaml/C#), my question is can I have two media-elements on a single page, one will always play some background music and second will play some other sound depending upon user actions?
I tried it but not working for me, only background music is getting played the other sound is not getting played.
I can't see problem. you can use 2 media elements on the same page. mediaControl1 plays always and mediaControl2 starts to play when user clicks on button.
<Button Width="150" Height="150" Style="{StaticResource ButtonAppStyle}" Click="MainPage_Loaded">
<MediaElement x:Name="mediaControl1" Height="400" Source="Assets/muzika.mp3" RealTimePlayback="True" IsLooping="True" />
<MediaElement x:Name="mediaControl2" Source="Assets/firework1.wav" IsMuted="True"/>
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
mediaControl2.IsMuted = false;
mediaControl2.Play();
}
I'm developing a simple Windows Phone 8 app and I have the keyboard show up correctly using the Url InputScope. At the bottom right corner of the soft keyboard (SIP) a right arrow is displayed.
How do I detect that the user clicks that button?
I've tried the KeyUp-event, but the Key class is not defined so I can't compare e.Key with Key.ENTER - and I also have a feeling that it isn't correct to check the key code, semantically speaking. I'd rather find some "onSubmit" event like in HTML.
I got it working by first adding "using System.Windows.Input;" to the top of my .cs file. After that the Key class became available.
XAML:
<TextBox KeyUp="txtUrl_KeyUp" x:Name="txtUrl" InputScope="Url" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" TextWrapping="Wrap" VerticalScrollBarVisibility="Disabled" ManipulationCompleted="txtUrl_ManipulationCompleted" Margin="0,127,0,0" Grid.RowSpan="2" />
C#:
private void txtUrl_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key.Equals(Key.Enter)) {
navigateTo(txtUrl.Text);
webBrowser.focus(); // Hides the input box
}
}