How to use background media player in Windows Phone Silverlight 8.1 - windows-phone-8

I am working on a Windows Phone application for Windows 8.1. I need to use features like Motion classes, Isolated Storage etc. As these features were not supported in Windows Phone 8.1 I went for Windows Phone Silverlight 8.1. Now I have to use BackgroundMediaPlayer in my project and Windows.Media.Playback is not supported in Windows Phone Silverlight 8.1. Is there any possible way by which i can use all the basic API's like:-
-Microsoft.Devices.Sensors
-Microsoft.Xna.Framework
-System.IO.IsolatedStorage-System.Windows.Media.Imaging
and use BackgroundMediaPlayer, Motion classes?? any help will be really useful.
Thanks,
Ekta

Playing Background audio differs in Windows Runtime and Silverlight (Overview). You were trying to use MediaPlayer which:
Minimum supported phone Windows Phone 8.1 [Windows Runtime apps only]
is only for runtime.
As for working with BackgroundAudioPlayer Class in Silverlight 8.1, there is a problem - it won't work. This is a limitation in Silverlight 8.1:
The AudioPlayerAgent and AudioStreamingAgent classes, which supported background audio playback for Windows Phone 8 apps, are not supported in Silverlight 8.1. If you want to support background audio playback, you can continue to use a Windows Phone 8 app or create a Windows Phone Store app, which supports new background audio APIs.
So in this case you will have to write app that target WP8.0 Silverlight or or WP8.1 Store app.
The similar question was here at MSDN forum.

You can achieve that by Creating a new Windows Runtime Component. This is where your entry point for the Audio task will be. The entry point is a class that implements IBackgroundTask. This gives you one method that will be invoked on startup of the Audio task named Run.
In order to keep the Task alive indefinitely you need to keep track of the deferral that exists on the IBackgroundTaskInstance. Placing the deferral in a field for safe keeping will be enough. When the operating system cancels your task you will need to call Complete on this said deferral.
An example of a bare bone implementation of your task should look something like the following
public sealed class AudioPlayer : IBackgroundTask
{
private BackgroundTaskDeferral _deferral;
public void Run(IBackgroundTaskInstance taskInstance)
{
_deferral = taskInstance.GetDeferral();
taskInstance.Canceled += TaskInstance_Canceled;
}
private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
{
_deferral.Complete();
}
}
for more Refrence you can go here

Related

Parse with Windows Phone 8 Universal Apps

I have a Windows 8.1 Universal app that I am using with Parse. I have downloaded the latest .NET libraries for Parse and included the Parse.dll and ParseWindows.dll in the Windows 8 project. The app works just fine with them.
I then include the Parse.dll and parsePhone.dll in the Windows Phone app. When the phone app runs, I get a FileNotFound exception when the ParseClient.initialize method is called. The method is in a static class within my Shared library, and is used by both projects. It works fine in the Windows 8 app, but throws the exception in the Windows Phone app.
This is the method that gets called, with the keys redacted.
public static class ParseCloudService
{
public static void InitializeParseCloudService()
{
try
{
ParseClient.Initialize("AppIdGoesHere", ".NETKey");
}
catch(ParseException)
{
throw;
}
}
}
Has anyone else ran in to this? Is there something that I'm supposed to be adding to the Windows Phone 8.1 app that the Parse library expects? Again, this is in a Universal app, and not a standard Windows Phone app project (previous posts I've made this gets confused).
Another interesting thing, is that even though I have this wrapped in a try/catch, the exception goes thrown within the Intialize() method, and never gets caught by my try/catch. If I set a break-point in my catch, the breakpoint never gets hit. It throws within Initialize(), then immediately breaks within app.g.i.cs file.
Could not load file or assembly 'System.Windows, Version=2.0.6.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.
and this is the stack trace:
at Parse.PlatformHooks.SettingsWrapper..ctor()
at Parse.PlatformHooks.SettingsWrapper.get_Wrapper()
at Parse.PlatformHooks.get_ApplicationSettings()
at Parse.ParseClient.get_ApplicationSettings()
at Parse.ParseClient.get_InstallationId()
at Parse.ParseClient.Initialize(String applicationId, String dotnetKey)
at Actions.Services.ParseCloud.ParseCloudService.InitializeParseCloudService()
at Actions.Services.ParseCloud.ParseCloudUserService..ctor()
at lambda_method(Closure , IBuilderContext )
at Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
Thanks in advance!
The Parse .NET SDK will not be updated to support Windows Phone 8.1.
Source: https://developers.facebook.com/bugs/327073484113608/

how to lock the screen programmatically in windows phone 8?

We can prevent the screen to lock using the below code
PhoneApplicationService.Current.ApplicationIdleMode = IdleDetectionMode.Disabled
and
PhoneApplicationService.Current.UserIdleDetectionMode= IdleDetectionMode.Disabled
but how to lock the screen from my app. Like the below app
http://www.windowsphone.com/en-us/store/app/one-touch-lockscreen/a3b1220b-1f9a-4bf0-93bc-21ed02792279
Thanks in advance
It's pretty hacky. It's not in the official API, so it could stop working at any time, just like the volume control API. Anyway, it you want to do it, you need to use this external method:
[System.Runtime.InteropServices.DllImport("ShellChromeAPI.dll")]
private extern static void Shell_TurnScreenOn(bool value);
For WP8.0 app this needs to be in a Windows Runtime Component (you should reference its output, as the project cannot be referenced).
From what I understand, though, this won't work on WP8.1 devices, so you'll need a separate WP8.1 app and I think it needs to be a XAML (Windows Store) app.
What #yasen wrote is correct.
[DllImport("ShellChromeAPI.dll")]
private extern static void Shell_TurnScreenOn(bool value);
I've tried the following cases:
Runtime 8.1 C# (Passed store certification)
Runtime 8.1 C++ with Runtime Component 8.1 C# (Haven't tried to publish this in store)
Silverlight/DirectX 8.0 C++ (Passed store certification)
Here's the link to my app that's using the last solution mentioned above.
http://www.windowsphone.com/s?appid=38bf5918-025e-4f23-b515-2cac451a84ab
And I've heard about cases in store using Silverlight that supports 8.0 and 8.1.
You can get Screen is locked or not by Windows.Phone.System.SystemProtection.ScreenLocked
but Unfortunately There is no way to lock the screen via code in Windows Phone 7.x or 8.

sound effects are not playing in my game

I am developing a game for windows phone. The target version of game is 7.1 and 7.1 games and apps will be supported on wp8 devices.
Here is my code:
public SoundEffect l1;
public SoundEffectInstance level1sound;
l1 = contentManager.Load<SoundEffect>("sound/level1");
level1sound = l1.CreateInstance();
level1sound.IsLooped = true;
level1sound.Play();
Gaming sounds are working fine in simulator of 7.1 but when I deploy on wp8 device nothing works.
How to fix this issue?
If you develop Silverlight game, you must call FrameworkDispatcher.Update() method in every frame to dispatch messages that are in the XNA Framework message queue
sound file properties should set to soundeffect type

What is the MvvmCross version of DeviceNetworkInformation.IsNetworkAvailable

I'm re-writing a Windows Phone app to make it cross platform using the excellent MvvmCross framework.
On Windows Phone I usually test DeviceNetworkInformation.IsNetworkAvailable to ensure I have a network connection before calling a REST service.
Is there a way of doing this in a cross-platform way using MvvmCross?
There is a cross-platform plugin Cirrious.MvvmCross.Plugins.Network specifically for Network functionality and this was originally built specifically to provide Reachability
However, sadly the WindowsPhone part of this isn't yet implemented! See https://github.com/MvvmCross/MvvmCross/blob/v3.1/Plugins/Cirrious/Network/Cirrious.MvvmCross.Plugins.Network.Phone/Plugin.cs
If you need Reachability within a cross-platform app including WindowsPhone, I'd probably opt for adding this Network plugin, and then also modifying your WindowsPhone Setup to register something like:
public class MyReachability : IMvxReachability
{
public bool IsHostReachable(string host)
return // something using DeviceNetworkInformation.IsNetworkAvailable
}
}
// registered in Setup using:
protected override void InitializeLastChance() {
base.InitializeLastChance();
Mvx.RegisterType<IMvxReachability, MyReachability>();
}
Longer term, I'd be happy to see a decent implementation pushed back into the MvvmCross repository.
Also linking this question to: MvvmCross Reachability on Windows Phone and Network state with mvvmcross?

Windows Phone 8 app: using Platform Invoke

I'm trying to use Platform Invoke functionality in Windows Phone 8 application and getting NotSupportedException.
I'm doing something like this:
[System.Runtime.InteropServices.DllImport("PhoneDLL1.dll")]
public static extern void CallMeInC(int num);
....
CallMeInC(100);
Am I doing something wrong or this functionality is not supported for Windows Phone 8 apps ?
Thanks,
Rafi
Unfortunately, DllImport is not supported in Windows Phone. Currenty, the only workaround is to write a native component that mimics the behavior of DllImport and then referene that component from your managed code project.
more info here: Forum thread on MSDN
and here: Blog post on how to combine native code and managed code in Windows Phone