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
Related
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.
I am using the MediaPlugin for Xamarin Forms and try to save the taken picture into a specific album in the gallary, this works fine uner Android but not under iOS. I also added the requierd permissions (NSPhotoLibraryAddUsageDescription and NSPhotoLibraryUsageDescription) into the Info.plist file.
file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions()
{
CompressionQuality= _defaultCompression,
SaveToAlbum = true,
Directory = "mynewAlbum",
Name = Guid.NewGuid().ToString() + ".jpg",
DefaultCamera = CameraDevice.Rear,
SaveMetaData = true,
Location = loc,
});
Any suggestions what I could do to make it working or is this not even possible with the MediaPlugin?
Look at this issue. MediaPlugin GitHub
Looks like it will be possible after James or someone else will implement.
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.
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+
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
},