I have an application, targeting mango devices, which plays music via a BackgroundAudioAgent. As such it integrates with the universal volume control (UVC).
Is there a way to detect when the application is launched by tapping the artists details in the UVC?
Alternatively, is there a way to set a deep link for the UVC to use?
I want this so that I can take the user to the "Now playing" page, rather than the main page, when the app is launched via the UVC.
Update
This also affects launching the app from the now playing tile in the Music & Video hub as the BackgroundAudioPlayer automatically integrates with this part of the hub.
Using MediaHistory Zune Hub integration solves this problem. It also passes the Marketplace Test Kit capability test step in the RC SDK, so that’s a good sign.
If you start from the example on MSDN, calling the following code from GetNextTrack() and GetPreviousTrack() in the background audio agent means that when you click UVC or Zune Now Playing you can get back the navigation query string you specify here…
private AudioTrack ChangeTrack()
{
AudioTrack track = _playList[currentTrackNumber];
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
Stream s = isoStore.OpenFile("ApplicationIcon.png", FileMode.Open);
MediaHistoryItem nowPlaying = new MediaHistoryItem();
nowPlaying.Title = "Background Audio is playing!";
nowPlaying.ImageStream = s;
nowPlaying.PlayerContext.Add("keyString", track.Title);
MediaHistory.Instance.NowPlaying = nowPlaying;
return track;
}
Related
I've been following the examples for using SkiaSharp with Xamarin Forms, particularly the section on using bitmaps. I'm doing this in Microsoft Visual Studio 2017 version 15.9.11. I'm only targeting Android currently.
This page https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/basics/bitmaps has a section on Loading a Bitmap Resource, where the bitmap is an embedded image resource in the project.
So, we add the image and make it type 'embedded resource'
and then run the example code to simply display the image on the canvas.
string resourceID = "SkiaTest.Media.monkey.png";
Assembly assembly = GetType().GetTypeInfo().Assembly;
using (Stream stream = assembly.GetManifestResourceStream(resourceID))
{
resourceBitmap = SKBitmap.Decode(stream);
}
All pretty simple, and it works fine if I run the code on my phone if it is connected via USB in the standard way (a Sony Z5) so the second in the list here, not the Player:
Here it is working via USB:
But if I try and use Xamarin Live Player (the first in the list above) then it crashes on this line:
using (Stream stream = assembly.GetManifestResourceStream(resourceID))
Note that the app runs fine in Live Player if I don't try and load the bitmap, it's only that line that triggers the crash, and only in Live Player.
So I wonder if anyone has any ideas what could be causing Live Player to fail over this issue? Is the resource not being copied to the phone? Does Live Player just not support this type of activity?
The reason you are facing this issue is that Embedded Resources are not yet supported by Xamarin Live player which is causing this exception.
More details can be found in the Troubleshooting Xamarin Live Player document.
I am developing an app for Wp7.x and Wp8 which runs YouTube Video with lock screen disabled.
I have seen that new version of MyTube App and Microsoft version of your tube app which has been pulled back had a feature which allows user to keep listening to Video(Audio part) when phone is locked via lock screen. I want to Develop a YouTube Radio type of app which keeps pulling new Specific type of Viedo Url from youTube site and play the audio part even if running in background or In a Locked screen.
See MyTube App in wp8 store to know more what I am talking about.
The Windows Phone application goes to dormant/tombstone mode when the phone screen is locked. This behavior can be altered by changing the properties UserIdleDetectionMode and ApplicationIdleDetectionMode of PhoneApplicationService class. By default UserIdleDetectionMode and ApplicationIdleDetectionMode are set to Enable, which allows the service to lock the phone when the user is idle and these deactivate the application when the phone is locked.
As shown below, I have used ApplicationIdleDetectionMode, which when set to Disable doesn't deactivate the application when the phone is locked.
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
PhoneApplicationFrame rootFrame = App.Current.RootVisual as PhoneApplicationFrame;
if (rootFrame != null)
{
rootFrame.Obscured += new EventHandler<ObscuredEventArgs>(rootFrame_Obscured);
rootFrame.Unobscured += new EventHandler(rootFrame_Unobscured);
}
Once ApplicationIdleDetectionMode is Disabled, it cannot be Enabled until the application is re-launched. If you try to enable it, it will throw an exception. To handle the locking and unlocking state of the device you can call the Obscured and Unobscured event handler of RootFrame. Obscured will be called when the phone is getting locked. Here we should use minimum CPU, less battery consumption etc. and Unobscured gets called when the phone is getting unlocked. This is the stage when we can resume all the states of the application.
In Windows Phone 8, you can actually give video URLs to the BackgroundAudioPlayer class and it will play them in the background. I use this technique in Podcaster to switch between audio and video, though it's a user interaction that triggers the switch.
Updated
In Windows Phone 7 this technique doesn't work. Furthermore, MediaElement will always pause video when the lock screen is shown (even if ApplicationIdleDetectionMode is disabled) and there's nothing you can do about it.
In short, you can work around it in WP8 but there's nothing you can do on WP7
I'm developing a windows phone app with a background player based on the windows phone 7.1 project template(so i have 2 projects). My question is how i dynamically set the list of tracks for the background player to play? I tried static fields but didn't work and my guess is that i have to define a resource in the app.xaml but how it is done exactly? I need to share a List and an integer.
Thanks for the help!
The audio agent won't be able to read any resources in the App object (app.xaml).
As far as I can see the only way to communicate between your app and the background audio is via the BackgroundAudioPlayer.Instance object, the AudioTrack (see especially the Tag property) and using files stored in Isolated Storage.
This is described on MSDN here.
Also check out the Background Audio player in the MSDN code samples.
I want to display the list of songs in current playing lists, If users play music in my app, I could know what playlist is playing but if they were playing in zune app then switch to my app, my song list will be empty, even though the playlists is still running.
For example: if users's playing a playlists in windows phone 7 by Zune app, then they navigate to my App, how do I get that current play lists?
The current Windows Phone 7 APIs only integrate with phone media via the MediaPlayerLauncher, which allows you to launch media from your application.
The Mango (7.1) APIs allow you to integrate with the media + video hub, however, the APIs are still pretty simple. You can determine the currently playing media via MediaHistory.NowPlaying.
MediaHistory.NowPlaying is of Type MediaHistoryItem which has the Properties Title and ImageStream. You could add the Title and Image to your collection.
You can use MediaPlayer.Queue property of static class MediaPlayer from Microsoft.Xna.Framework library
I would like to launch directly to the YouTube player on Windows Phone 7.
I tried using WebBrowserTask and giving a YouTube URL, it opens up the browser and brings me to a page with a thumbnail of the YouTube video, I need to click on the thumbnail before the video plays.
I like to skip the extra click. I like the user to click a button in my app, and it should play the video directly. Is there a way to do it?
Once you have the Youtube app installed, from within you application you can start the WebBrowserTask and do the follwing:
Regex Youtube = new Regex("youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)");
Match youtubeMatch = Youtube.Match(YOUTUBE_VIDEO_URL);
string id = string.Empty;
if (youtubeMatch.Success)
id = youtubeMatch.Groups[1].Value;
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.URL = "vnd.youtube:"+ id +"?vndapp=youtube_mobile";
webBrowserTask.Show();
That should launch the browser, then automatically launch the Youtube App. Cheers!
Finally I've worked out a clean solution (without browser task, and no "double back key pressing"):
http://mytoolkit.codeplex.com/wikipage?title=YouTube
Try to use following sample;
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri("http://www.youtube.com/embed/V3oJR5IAMxM?autoplay=1");
webBrowserTask.Show();
this should open video directly, but I think you will have to still double click to go back.
There is a solution for that now. You can use vnd.youtube protocol to launch the YouTube application from Microsoft and play.
C#
Windows.System.Launcher.LaunchUriAsync(
new System.Uri("vnd.youtube:9bZkp7q19f0")
);
Unfortunately Launcher.LaunchUriAsync method only works with Windows Phone 8 devices and beyond.
No. Mabe in next version of OS will be custom choosers and lunchers.
To display a video from YouTube, you will need the Video Player for YouTube. Otherwise, you will need to write a custom decoder that will receive the YouTube stream and display it in a MediaElement.
As you've discovered this isn't currently possible.
There is currently no way to launch another application, other than by using a Launcher or Chooser.
On the YouTube site, individual videos can be configured to autoplay or not. I'm not aware of a way to override this.
However, on the phone this is different. YouTube uses flash to play videos but Flash is not currently supported on the phone. YouTube videos can only be played if the YouTube application is installed. When you open the youtube site with the webbrowsertask the user must click on the image to launch the player.
If web pages were able to launch applications without first requiring user action this could be a huge security issue.
N.B. The YouTube app has special elevated privileges, not generally available, to be able to be launched in the way it is.