notify user to play sound windows phone 8 and stop current music - audio

In my Windows Phone 7 and 7.5 apps I used to prompt a message box when the app was launched if the user was already playing music, to notify the user to stop current music to play the sounds, or to exit the app, this was working, but when I coded from the beginning for Windows Phone 8, for some reason this code doesn't work, if you are playing a sound, instead to prompt the notification, the apps opens and close itself.
This is the code I was using:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
FrameworkDispatcher.Update();
if (MediaPlayer.GameHasControl != true)
{
if (MessageBox.Show("This application requires play sounds and stop your currently playlist", "Information",
MessageBoxButton.OK) == MessageBoxResult.OK)
{
MediaPlayer.Stop();
FrameworkDispatcher.Update();
}
}
}
I'm pretty sure must be some change in the Api with the MediaPlayer? I couldn't find any information about that, someone knows how can I fix that?
Thanks!!!

As you guessed,there are some changes in APIs.
First thing I notice, calling MessageBox.Show(string) from the Application_Launching event causes an exception. You app is probably shutting down due to an unhandled exception.
From MSDN: "If you call Show(String) method from the app Activated and Launching event handlers an InvalidOperationException is thrown with the message Error Displaying MessageBox."
EDIT: The documentation on MSDN is unclear whether calling .Show(string, string, messageBoxButton) raises the same exception.
App platform compatibility for Windows Phone

Related

How to send silent push notification IOS13? Doesn't work since update (Xamarin.ios)

Our app has to receive silent notification from a service to work properly. Like check-in now with location info...etc.
It worked perfectly before IOS13. However it stopped working since the update. The phone receive the silent notification but IOS never wakes the app to process it if the app is in background.
I use the new headers :
request.Headers.Add("apns-id", Guid.NewGuid().ToString("D"));
request.Headers.Add("apns-push-type", "background");
request.Headers.Add("apns-priority", "5"));
request.Headers.Add("apns-topic", {BundleId});
My payload worked before however I tried the one from Apple docs as well still no luck :
{
"aps" : {
"content-available" : 1
},
"acme1" : "bar",
"acme2" : 42
}
I found on Apple forum few workarounds like send empty alert object..etc. I tried all of them still no luck.
And this all worked perfectly before IOS13!
Is anyone have any idea what is going on with the silent push notifications now on IOS13 and how to actually send one ?!
Update: maybe important info, I can send alerted notification so pushtoken..etc must be ok.
Also, when the phone connected to the Mac (not debugging, only connect trough USB) I get the silent notifications and the app waken up as before.
Found a workaround! I send a normal alerted message with the proper alert header, but add the content-available:1, then IOS13 does not show the notification, only lights the phone up for a sec, and wakes my application to process the message!
I have to send NOT the silent message format (with the "background" header)!!!, but the proper alerted message, like a normal push notification, but with content-available included!

Azure Notifications to WP and iOS

My app uses an Azure Notification Hub to send messages to both Windows Phone and iOS devices. The problem is that they work if one is called, but it doesn't work if both are called.
For example, If I send a message to an iOS device from my iOS emulator, the following code works fine and the notification appears.
var toast = PrepareMpnsToastPayload("myapp", notificationText);
var appleToast = PrepareAppleToastPayload("myapp", notificationText);
//await NotificationHelper.Instance.Hub.SendMpnsNativeNotificationAsync(toast, userTag);
await NotificationHelper.Instance.Hub.SendAppleNativeNotificationAsync(appleToast, userTag);
However, if I uncomment the SendMpns..() line, the notification never gets to the apple device. When stepping through this code with remote debugging, the call to SendMpns..() doesn't seem to return. I step over it and it just resumes.. and the breakpoint on the SendApple..() call below it never gets hit.
This works the same with the Windows Phone Mpns line (works fine without the apple call).
How am I supposed to send an alert to a user when I don't know what device they are on? I just want to send the notification to all types. Any pointers would be greatly appreciated.
EDIT: The below answers of removing await() did work. However as I now have authenticated notification hub I need to capture the return value of the call so I can see if I need to get another auth token if it has expired!
If posted code runs as trivial console application then we should wait for tasks to be completed. Easiest way to do so is removing await and calling Wait() against Task object returned by xAsync() methods:
NotificationHelper.Instance.Hub.SendMpnsNativeNotificationAsync(toast, userTag).Wait();
NotificationHelper.Instance.Hub.SendAppleNativeNotificationAsync(appleToast, userTag).Wait();

How to Play Youtube Videos In Windows phone 8 application? and make application Resolution compatible

Hello I am developing a windows phone 8 application. My application is complete i am left with two things
first, i have to play videos from youtube channel.
second, i have to make application resolution compatible.
I visited so many pages but no luck.
can someone help me out, My deadline for application submission is near.
You should add MyToolkit.Extended package from NuGet.
try
{
var videoUri = await MyToolkit.Multimedia.YouTube.GetVideoUriAsync(
"uRs4hz1YEQc", MyToolkit.Multimedia.YouTubeQuality.QualityMedium);
MediaYouTubeVideo.Source = videoUri.Uri;
}
catch (Exception exception)
{
// TODO: Show error
}
Have to say that I have not checked the example, but at least the details on the page suggest that you an use it for playing you tube videos: http://code.msdn.microsoft.com/wpapps/Youtube-Video-Sample-f2692dc9

how to integrate vserv ads sdk to windows phone 8 application

I have developed a windows phone 8 application. Now I want to display vserv ads to my application.
I have added the sdk to my application and also applied code to show ads:
public MainPage()
{
InitializeComponent();
VservAdControl VMB = VservAdControl.Instance;
VMB.DisplayAd(zoneID, LayoutRoot);
VMB.VservAdClosed += new EventHandler(VACCallback_OnVservAdClosing);
VMB.VservAdNoFill += new EventHandler(VACCallback_OnVservAdNoFill);
}
void VACCallback_OnVservAdClosing(object sender, EventArgs e)
{
MessageBox.Show("Ad close by user.");
}
void VACCallback_OnVservAdNoFill(object sender, EventArgs e)
{
if (adGrid != null)
adGrid.Visibility = Visibility.Collapsed;
}
But after closing the ad the application page goes blank, all content, application bar automatically goes blank. After using back arrow that quits my application, i try to relaunch my application but application stuck at the splash screen on the emulator.
Wrap ad control inside a grid. Ad control could have manipulated the grid
I encountered the same issue and they have updated their SDK several times. If you provide the stacktrace they will provide you a fix.
Apart from what you have seen, there are other issues with the SDK. I integrated it few weeks back. So issues could have been resolved after that.
Memory leak. Click the ad or navigate back and forth - you will see the memory ever growing. This is because of events not being detached (withing SDK). I was consistently able to see my app crash in 512 MB emulator when banner ad is loaded (after 4 - 5 times). They could have used weak listeners. You might need to tweak a lot to overcome this issue (In multi page app)
RequestAdCallback throws null pointer exception sometimes crashing
the app. When people use app, they will navigate fast - forcing the
webbrowser to unload. All callbacks should be null pointer exception
free. Make sure that you handle unhandled exception globally otherwise app will not pass certification
It reads WMAppManifest.xml as text not as XML. So I had App element commented in first line before the actual one. It picked title from commented XML element
Application bar is manipulated in many events in the SDK. So you have to make sure that app bar is built dynamically. Test all navigation paths.
SDK assumes user will click the left arrow button which fires ad closing event. Try pressing phone back button instead. The app bar still disappears
SDK documentation requests app to demand ID_CAP_REMOVABLE_STORAGE capability. I don't see a reason to request this capability but I didn't add this
I have emailed them all these details. May be their latest SDK could have resolved these issues. But please do thorough testing after integration.
Add a function to load applicationbar using code
private void BuildLocalizedApplicationBar()
{
// Set the page's ApplicationBar to a new instance of ApplicationBar.
ApplicationBar = new ApplicationBar();
ApplicationBar.Mode = ApplicationBarMode.Default;
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsVisible = true;
ApplicationBar.IsMenuEnabled = false;
// Create a new button and set the text value to the localized string from AppResources.
ApplicationBarIconButton button1 = new ApplicationBarIconButton();
button1.IconUri = new Uri("/Images/sms.png", UriKind.Relative);
button1.Text = "sms";
ApplicationBar.Buttons.Add(button1);
}
and then in VACCallback_OnVservAdClosing event handler call the function
BuildLocalizedApplicationBar()
Please check the following link,
where to add application id and adUnitiD while integrating vserv ads sdk to windows phone 8 application, which is related to your question.

How to resume iPhone app after a Phone Call

I am creating an iPhone app in which I am providing a call feature with the help of which a user can call place a call on a specified number. I am able achieve the above feature via open URL.
Now after completion of the call I want to resume the execution of app automatically. Although a user can make a fast app switch in iOS 4.0. but I want this to be done automatically.
I have seen the same behavior in "TomTom" app but I am not sure how this app has achieved it.
Thanks
Sandy
Apple does not allow you to resume an app after a phone call. What you can however try doing is using a local notification.
After calling the 'call' url handler you will need to start a background task and monitor for a call state change:
CTCallCenter *c=[[CTCallCenter alloc] init];
c.callEventHandler=^(CTCall* call){
if(call.callState == CTCallStateDisconnected) {
// do stuff here
}
}
When you get a call state change, create a local notification to alert the user to resume the app. If the user taps on "view" your application will then come to the foreground. Obviously if the call is longer than 10 minutes this won't work as Apple only allows 10 minutes to background tasks.

Resources