I am working on an application that plays a video using the MediaElement component. Now, I would like that if the user is idle, the lock screen appears, as configured by the user in the Settings of the device.
If I don't play a video, the lock screen indeed appears. But, when a video is playing no lock screen appears. I cannot find any information on this.
Currently I set the idle detection modes like this:
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Enabled;
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Enabled;
I am a bit lost now. The only solution I can think of is running a timer myself and stop the video playback after a certain time. (but there seems to be no API calls to receive the configured lock timeout.)
Any suggestions are welcome, thanks.
One workaround for you would be to enable running under the lockscreen. Then in the obscured even you could stop the mediaplayer. Not ideal, but it might serve your purposes.
Related
I'm working on a Unity project that uses the device camera for AR purposes (I'm using AR Foundation). I currently have it set so that the device won't go to sleep (because I want it to operate for long-periods without user-interaction). Specifically, Screen.sleepTImeout = SleepTimeout.NeverSleep. If I didn't have this, then the device would go to sleep, and the program would stop functioning. Does anyone know if there is a way to keep the program working in the background after the device goes to sleep...similar to how music apps keep playing music? I've come up empty handed after a few hours of searching for a solution. Any help would be greatly appreciated!!!
Some people aren't finding this in more recent versions of Unity. But it's still there: In Player settings, under the section "Resolution and Presentation", you find "Resolution" and below that, there's "Run In Background".
This is only available for Web players and standalones (Anything Except IOS And Android Pretty Much), though (you won't find it when you have the iOS, Android or Flash tab selected.
I am search for a way to detect if video is playing on Windows OS (7,8,10).
SetThreadExecutionState api function does not help I have tryied with different players (VLC, BS player etc.) but it seems they don't use flag ES_DISPLAY_REQUIRED.
Checking for disabled screensaver is not good solution, because it should be allowed at first place and almost nobody use screensavers nowdays.
My app is a break timer, I am using LASTINPUTINFO() function but I want to know
when the user is watching video because there is not input (keyboard or mouse) during this time.
A dirty and partial solution would be if the app does snapshot of region in the center of the screen and comparing hashes, but it will be 90% accurate.
Any better ideas?
I have an application that uses MediElement to play videos and provides it with a custom video effects implemented in C++\CX via MediaElement.AddVideoEffect method.
https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.mediaelement.addvideoeffect
And it works just fine. But there is a bit of a problem, - When user hits the "Pause" button, MediaElement stops calling ProccessFrame method of the video effects I attach. Which leads to the situation, when user can tweak his effect whilst video is playing, but cannot do it on Pause.
So basically, I'm wondering if there is a workaround.
Thank you for the time and effort.
Kind regards.
I have built a Windows Phone application with a video player to show a logo animation at startup.
If I launch an external application (like Spotify) with background audio (for example a song) and then switch to my application, the song is stopped (probably because of my logo animation) even though my logo animation doesn't even have audio.
I used a MediaElement for the logo animation :
<MediaElement AutoPlay="False" Name="media" Source="Assets/video.mp4"/>
In the code behind I use media.play(); to start the logo animation.
Is there a way to avoid stopping the sound of other applications?
From the MSDN:
When a MediaElement control plays audio or video content, any
background sounds or media already playing are halted. The app
launches the playback experience when the user taps the control. Only
one MediaElement control can operate at a time.
What this means for you is that you need to redesign the logo to run via XAML animations or some other means besides MediaElement if you want background audio to function properly. Depending on where your animation is coming from, this might be simple for you or it might be outside your scope. You'll have to determine for yourself if the benefits of background audio (Pandora, Spotify, Podcasts, etc) outweighs the work required.
That being said, I've used a large number (probably 20% in my testing) of apps that cancel background audio every time you enter them, and it's extremely frustrating. I think most users would prefer you fixed your application so that background audio is not interrupted.
I have researched a lot on playing sounds for Windows Phone 8 devices and found multiple solutions but they don't quite match my case.
What I need : I'm writing an app (C#+XAML) that uses a file as background sound (must be active while navigating the whole app), and also to be able to play sound effects.
What are the issues :
For background sound I could use the BackgroundAudio Agent, but it doesn't meet my requirements because I want the sound to be played only in the background of my app, and to stop if my app closes or is not active.
For sound effects - I tried MediaElement which is okay, but I couldn't manage to make it somehow play while I am navigating the whole app. Media closes if I leave that page - I guess I could use this for the sound effects trick. Also, there's the SoundEffect which is not quite a good solution since it can play only .wav files... I could use it for sound effects only but not background sound (big sized files).
So, how should I proceed to play background sound (only inside my app) if I choose MediaElement/SoundEffect to play a sound effect in the app. I need a solution that would allow me to play 2 sounds at once (background and sound effect) and the background sound to be played only while the app runs (is active)...
So far I am confused and managed only to solve the sound effects issue.
Any suggestions are greatly appreciated.
The issue you are seeing with your MediaElement is that you are defining it to be part of the application page and it stops playing as soon as it disappears off of the Visual Tree (i.e. after OnNavigatedFrom).
If you define a MediaElement to be "visible" as part of the application frame, audio will keep playing while your app is active (you will need to handle deactivation events, naturally).
If you do this MediaElement should work for your "background audio".
Be aware you can only have one single active MediaElement playing media in your app, however you should be able to use SoundEffect for your sound effects.
Update:
To put your MediaElement in a frame, you will need to create a custom PhoneApplicationFrame class/XAML, add the MediaElement to that XAML, and refer to your custom frame in App.xaml.cs.
// Do not add any additional code to this method
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new MyCustomPhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
See this Dzone article for more about Frame/Page in Windows Phone.
In practice, MediaElement is has some gotchas like the visual tree requirement. There are ways to get around it, but they are not optimal. I would suggest scrapping using MediaElement and use XAudio2 instead. It is native so default usage would be in c++, but you can also use SharpDX to access this framework from C#.
The advantage of XAudio2 is that you would not need to worry about sound dropping out when navigating around since it is not dependent on the UI. Another advantage is you could have one SourceVoice for handling your background audio, and other SourceVoices for handling sound effect playback. This all fits well within the model of usage the framework was designed for.