How to use Nokia Music Api in Windows Phone 8 - c#

I am used following code to get Genre using Nokia Music API.
client.GetGenres((ListResponse<Genre> response) =>
{
Dispatcher.BeginInvoke(() =>
{
this.Generic.ItemsSource = response.Result.ToList();
if (response.Result == null || response.Result.Count() == 0)
MessageBox.Show("No Result available");
});
});
I am successfully getting the genre and all details but how can i retrieve the all tracks and play the selected one Track.

According to the Nokia Developer API Documentation
In order to play a specific artist use the nokia API Music Launcher
The following method from Music Explorer's MusicApi shows how simple
it is to launch Nokia Music application to play artist mix. Nokia
Music app can be launched just as easily into a product or artist
state using Nokia Music API. Some of the launcher methods in Nokia
Music API require unique ids of artists, mixes and products. These ids
are received in responses from Nokia Music API's other services.
using Nokia.Music.Phone;
using Nokia.Music.Phone.Tasks;
...
namespace MusicExplorer
{
...
public class MusicApi
{
...
public void LaunchArtistMix(string artistName)
{
...
PlayMixTask task = new PlayMixTask();
task.ArtistName = artistName;
task.Show();
}
...
}
}
I don't see anything specifc about listing album contents but you can probably leverage GetArtistProducts() to do this
client.GetArtistProducts(
(ListResponse<Product> response) =>
{
// Use results
},

Related

how do i get Android.Media.SetPreferredDevice() to work

So making a mobile application that works on UWP, IOS and Android but since not all librarys work on every platform I'm using the library based on what device is used by
if (Device.RuntimePlatform == Device.Android) { }
And I'm currently only working on the Android part of the application.
I'm using Android.Media to play a single audio file out of multiple speakers. And to do that I'm using a Picker that has the available audio output devices. This part works.
But I'm getting a error while trying to select the PreferredDevice:
Java.Lang.NoSuchMethodError: 'no non-static method "Landroid/media/MediaPlayer;.setPreferredDevice(Landroid/media/AudioDeviceInfo;)Z"'
The code line that is giving the error is:
mediaPlayer1.SetPreferredDevice(audioDeviceInfo);
the full method that is being run is:
newoutput.SelectedIndexChanged += (changed, args) =>
{
Context context = Android.App.Application.Context;
AudioManager audioMan = (AudioManager)context.GetSystemService(Context.AudioService);
AudioDeviceInfo audioDeviceInfo = audioMan.GetDevices(GetDevicesTargets.Outputs)[newoutput.SelectedIndex];
mediaPlayer1.SetPreferredDevice(audioDeviceInfo);
};
I can't find many examples that use the method and they don't usually go with a mediaplayer that is created by button press.
You can use this code
private AudioDeviceInfo findAudioDevice(int deviceType) {
AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
AudioDeviceInfo[] adis = manager.getDevices(GET_DEVICES_OUTPUTS);
for (AudioDeviceInfo adi : adis) {
if (adi.getType() == deviceType) {
return adi;
}
}
return null;
}
Then set your input:
audioRecord.setPreferredDevice(findAudioDevice([newoutput.SelectedIndex]));

Playing in-built webcam feed in a UWP app stopped working after?

I'm trying to play the built-in webcam feed in a MediaElement within a UWP app. It works fine for a few users but there is no feed played for most and I'm lost on what could be the issue.
Some observations when the webcam feed doesn't play:
The code executes without any exceptions
The dialog that requests user permission to access the camera is shown
The LED indicating the webcam is in use turns on soon as it is executed, but there is no feed.
Skype and Camera apps work fine.
The app was working as expected until a week back. A few things that changed in the mean time that could have had an impact are
Installed Kaspersky
A bunch of windows updates
Uninstalled VS2017 professional edition & VS2019 Community edition and installed VS2019 Professional Edition
Some additional information that might be needed to narrow down the reason.
Webcam is enabled in the Package manifest of the app
App Target version: 18362
App Min version: 18362
Windows OS Version : 18362
Any help on this would be highly appreciated. Thanks much in advance!
Here is the piece of code used to play the webcam feed where VideoStreamer is a MediaElement.
private async Task PlayLiveVideo()
{
var allGroups = await MediaFrameSourceGroup.FindAllAsync();
var eligibleGroups = allGroups.Select(g => new
{
Group = g,
// For each source kind, find the source which offers that kind of media frame,
// or null if there is no such source.
SourceInfos = new MediaFrameSourceInfo[]
{
g.SourceInfos.FirstOrDefault(info => info.DeviceInformation?.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front
&& info.SourceKind == MediaFrameSourceKind.Color),
g.SourceInfos.FirstOrDefault(info => info.DeviceInformation?.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back
&& info.SourceKind == MediaFrameSourceKind.Color)
}
}).Where(g => g.SourceInfos.Any(info => info != null)).ToList();
if (eligibleGroups.Count == 0)
{
System.Diagnostics.Debug.WriteLine("No source group with front and back-facing camera found.");
return;
}
var selectedGroupIndex = 0; // Select the first eligible group
MediaFrameSourceGroup selectedGroup = eligibleGroups[selectedGroupIndex].Group;
MediaFrameSourceInfo frontSourceInfo = selectedGroup.SourceInfos[0];
MediaCapture mediaCapture = new MediaCapture();
MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings()
{
SourceGroup = selectedGroup,
SharingMode = MediaCaptureSharingMode.ExclusiveControl,
MemoryPreference = MediaCaptureMemoryPreference.Cpu,
StreamingCaptureMode = StreamingCaptureMode.Video,
};
try
{
await mediaCapture.InitializeAsync(settings);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("MediaCapture initialization failed: " + ex.Message);
return;
}
var frameMediaSource1 = MediaSource.CreateFromMediaFrameSource(mediaCapture.FrameSources[frontSourceInfo.Id]);
VideoStreamer.SetPlaybackSource(frameMediaSource1);
VideoStreamer.Play();
}
As mentioned by Faywang-MSFT here , it worked after marking the application as trusted in Kaspersky.

Control Widows Media Device Flash Light

I am trying to create a simple application which will have the functionality to switch on and off the flash light in a Windows Media Device.
I have initialized the camera as following:
var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
var rearCamera = devices.FirstOrDefault(item => item.EnclosureLocation != null &&
item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
if (rearCamera != null)
{
DeviceName.Content = rearCamera.Name;
FlashButton.Visibility = System.Windows.Visibility.Visible;
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
{
VideoDeviceId = rearCamera.Id
});
LowLagPhotoCapture lowLagCaptureMgr = null;
// Image properties
ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
// Create LowLagPhotoCapture object
lowLagCaptureMgr = await mediaCapture.PrepareLowLagPhotoCaptureAsync(imgFormat);
}
And to switch on the flash I have written the following code:
var MyVideoDeviceController = mediaCapture.VideoDeviceController;
var MyTorch = MyVideoDeviceController.TorchControl;
var MyFlash = MyVideoDeviceController.FlashControl;
if (MyTorch.Supported)
{
MyTorch.PowerPercent = 100;
MyTorch.Enabled = true;
}
else
{
if (MyFlash.Supported)
{
MyFlash.PowerPercent = 100;
MyFlash.Enabled = true;
}
else
{
MessageBox.Show("No Flash and Torch Support", "Flash and Torch");
}
}
But seems both TorchControl and FlashControl are not supported in the code. I am not sure if am using the right APIs too. I am trying to run this on a Motion F5m - Tablet PC
Thanks in advance
The TorchControl is used for constant video light, so if you're taking a photograph, it's not the most appropriate control to use. One reason is that on many devices, video light will be dimmer than a photo flash, but especially because on some devices, the torch will only turn on while a video recording is in progress. Depending on the capabilities of the device, this may interfere with the ability to take photos.
You have the right idea setting MyFlash.Enabled = true, but just to be safe, I would also set MyFlash.Auto = false, so that the flash will fire each time, and not only when it's dark.
The CameraManualControls sample on the Microsoft GitHub repository shows you how to use the Flash and Torch controls, and many more. It targets Windows 10, though, so if you're on 8.1 you'll have to adapt the code or upgrade your tablet.
Now, all of the above is assuming that the device you're running your app on has flash support in the first place. When you say that the controls are not supported, that means that the camera driver on the device is not advertising the capability to Windows. I assume that the built-in Microsoft Camera app doesn't allow you to use the flash either?
I see the manufacturer of your tablet lists an "Illuminator Light" on their camera specs list, but there is a chance that the only way to control it is through their proprietary application. In that case you'd have to reach out to them for support.

Getting Local Photos Windows Phone 8 Emulator

So I have taken some Photos on my windows phone emulator and I am then trying to find them in my application.
So Far I have:
PictureCollection CameraRollPictures;
using (var library = new MediaLibrary())
{
//taking all albums
PictureAlbumCollection allAlbums = library.RootPictureAlbum.Albums;
//taking Camera Roll album separately from all album
PictureAlbum cameraRoll = allAlbums.Where(album => album.Name == "Camera Roll").FirstOrDefault();
// here you will get camera roll picture list
CameraRollPictures = cameraRoll.Pictures;
}
But this keeps crashing because cameraRoll = null. Is this feature available on WP8 emulator or am I doing something wrong?
My method to get photos is from this stackoverflow question
EDIT
I have also tried album.Name == "Camera Roll"
So the answer was simple... My method worked perfectly but I needed to:
go into the WMAppManifest.Xml
go to Capabilities
tick ID_CAP_MEDIALIB_PHOTO
This provides read-only access to photos in the media library
MediaSource mediaSource = MediaSource.GetAvailableMediaSources()
.First((source => source.MediaSourceType == MediaSourceType.LocalDevice));
using (MediaLibrary mediaLibrary = new MediaLibrary(mediaSource))
{
PictureAlbum cameraRollAlbum = mediaLibrary.RootPictureAlbum.Albums.First((album) => album.Name == "Camera Roll");
}
or use PhotoChooserTask
You can upload Images to an Emulator as mentioned here

There is a better way to get picture information on Windows Phone?

I'm developing an application for Windows Phone 8 and I need to choose a picture from MediaLibrary. I'm using the PhotoChooserTask but the PhotoResult does't have information about the picture (like creation date).
I've tried to use the File.GetCreationTime method but it gives me UnauthorizedAccessException
For now, to get the file creation date I'm using the following code:
{
PhotoChooserTask chooserTask = new PhotoChooserTask();
chooserTask.Completed += (obj, result) =>
{
if (result.ChosenPhoto != null)
{
String fileName = Path.GetFileName(result.OriginalFileName);
String albumName = Path.GetFileName(
Path.GetDirectoryName(result.OriginalFileName));
//Get album by name
PictureAlbum album = MediaLib.RootPictureAlbum.Albums
.First(item => item.Name == albumName);
if (album != null)
{
//Get album picture by name
Picture picture = album.Pictures
.First(item => item.Name == fileName);
if (picture != null)
{
//Do Something
}
}
}
};
chooserTask.Show();
}
My question is, do we have a better way to get this information without iterate over all (worst case scenario) pictures in the album? Or Am I forgetting to setup some capability to
be able to use the File.GetCreationTime?
Well, phone albums will not have millions of photos to iterate through but if exists a direct way to get this information I would like to know. :)
Thanks
Best Regards
You should look into EXIF data. EXIF data are metadata that contains things like GPS coordinates of where the picture was taken, photo orientation, date taken, etc.
Search for ExifLib in NuGet. It will add you a Windows Phone compatible library that allows reading EXIF metadata.
Info about that library here: ExifLib - A Fast Exif Data Extractor for .NET 2.0+

Categories

Resources