I am developing one Flash Light application in Silverlight for windows phone 8. Currently
I am deeply stuck in one issue for the use of "Microsoft.Phone.Media.Extended" assembly. Flash Light Application for Windows phone 7 is already live in Windows Phone Marketplace and it is working very fine for Windows Phone 7 but it is not working for Windows Phone 8 because of "Microsoft.Phone.Media.Extended" dll.
After converting WP7 app into wp8 and run then I got this type of error message:
Could not load file or assembly 'Microsoft.Phone.Media.Extended,Version=7.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e' or one of its dependencies. The system can not find file specific."
According to following link for Windows Phone-specific features:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206947(v=vs.105).aspx
If you were using reflection to access the API in this assembly, because they were not publicly exposed, your app may fail on a Windows Phone 8 device. Remove the calls to this assembly and use the publicly exposed media API.
I an not understanding how to use publicly exposed media API. I used Microsoft.Phone.Media.Extended using reflaction in Windows Phone 7. Is there any direct method for accessing Microsoft.Phone.Media.Extended in Windows Phone 8 or other way to solve this?
Thanks.
==========================================================================
Edited Question:
Hi,
As per the thread, we used "VideoTorchMode" enumeration to make flashlight ON. As per that, I used AudioVideoCaptureDevice class using Windows.Phone.Media.Capture namespace with following code:
var objDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, AudioVideoCaptureDevice.GetAvailableCaptureResolution(CameraSensorLocation.Back).First());
objDevice .SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
I want to keep the flash light on but without capturing video. So, i have not initialized video capture code. The issue is, i don’t have WP8 yet and in simulator i am not able to test this.
Can any one confirm that once i put this code, my app will work as Flashlight-X where light will be on without blinking and also it will not get crashed in WP8.
Thanks
Microsoft.Phone.Media.Extended is a private API in WP7 that wasn't meant to be used by 3rd party developers. That API doesn't exist or works on WP8.
For WP8 flashlight use the AudioVideoCaptureDevice known property of VideoTorchMode=On. Also, make sure to handle failures like exceptions or devices that don't have a Camera Torch by showing a white screen.
Here's a code sample that turns on the camera flash on my Lumia 820 and Lumia 920:
var sensorLocation = CameraSensorLocation.Back;
try
{
// get the AudioViceoCaptureDevice
var avDevice = await AudioVideoCaptureDevice.OpenAsync(sensorLocation,
AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation).First());
// turn flashlight on
var supportedCameraModes = AudioVideoCaptureDevice
.GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode);
if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
{
avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
// set flash power to maxinum
avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower,
AudioVideoCaptureDevice.GetSupportedPropertyRange(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max);
}
else
{
ShowWhiteScreenInsteadOfCameraTorch();
}
}
catch(Exception ex)
{
// Flashlight isn't supported on this device, instead show a White Screen as the flash light
ShowWhiteScreenInsteadOfCameraTorch();
}
Make sure to add the required capabilities and requirements to your WP8 app when using the camera torch (ISV_Camera, Microphone, and ID_REQ_BACK_Camera).
What about getting this assembly from somewhere and adding it to your XAP directly (try asking on XDA developers)? This might work, if it's signed and not requiring any special capabilities.
If you use the new API to "record" a video, then using the VideoTorchMode enumeration might do just want you want to create a "flashlight" effect.
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'm trying to do something very simple: implement a program that activates the back camera of my WP8 device. Could anyone help me do that?
If so you could try using the PhotoCamera class in order to capture images. I'm not pretty sure whether you'll be able to open the native Camera app of the device.
References:
How to access the camera from my Windows Phone 8 app (XAML and C#) and save the taken picture in a determined folder?
Sample from MSDN
Minimal Camera app in Windows Phone
I have an existing application developed for Windows Phone 7, which uses CameraCaptureTask.
The captured image is returned back to the app, which will be processed for grayscale conversion.
While testing the same app (same binary to be precise) in Windows Phone 8 Lumia 920, I figured that a copy of all the images captured through the CameraCaptureTask are saved in "camera roll" folder.
This is a bit annoying as the users of my app are not expecting the captured images crowding the "camera roll" folder. I looked up the documentation http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394006(v=vs.105).aspx and found the below quote,
On Windows Phone 8, if the user accepts a photo taken with the camera capture task, the photo is automatically saved to the phone’s camera roll. On previous versions of Windows Phone, the photo is not automatically saved.
So far I couldn't find a way to avoid this case in Windows Phone 8.
Is there a way to turn off this feature before calling the CameraCaptureTask's Show() method in Windows Phone 8?
No. This is a consumer feature request implemented on WP8 that's transparent to developers. The usecase here is that a consumer uses the CameraCaptureTask to line up a perfect shot, doesn't use it an app for whatever reason and can't find it ever again later.
As a side-note, I actually had this happen a few times to me when using various twitter and photo editing apps and it's quite annoying.
Makes no sense. CameraCaptureTask was created to allow apps to capture photos for the app use, not for users to push them into Camera Roll. That is what Lenses are for (either custom code can write into camera roll as well).
It is not transparent to developers because one of my apps has just been removed from the WP8 market. They say because can cause "undesired upload of an app photo to skydrive".
Justin are you sure it isn't a bug? is it going to be fixed?
This forces me to break my development into 2 now: WP7 and WP8. I don't want that hassle right now...
Does anybody know how to access the Xbox Live Avatar from within an XNA based Windows Phone 7 application?
Examples I have found seem to use a SignedInGamer.Avatar property, but this is not accessible from Windows Phone 7.
Is there another way or is this not possible in the first place?
as a side note, I'm using the recent Mango beta 7.1 SDK
Thanks!
It's not available in code unless you have the elevated privileges of access to XBox live.
You can, however get an image of your avatar from the web. try:
http://avatar.xboxlive.com/avatar/XXXXXXX/avatar-body.png
where xxxxx is the XBox account name. e.g. http://avatar.xboxlive.com/avatar/kris/avatar-body.png
My understanding is they are only available to partners. See this post for more information:
http://www.ozymandias.com/how-do-i-use-xbox-live-apis-on-windows-phone
However, it looks like you can demo them, here's a quick tutorial on using them:
http://xnaessentials.com/archive/2009/06/11/xna-game-studio-3-1-avatar-tutorial.aspx
I know that Microsoft hasn't officially supported doing any video capture applications as of yet. I've found the Clarity Consulting blog entry that highlights how to use the camera through Silverlight (entry is here: http://blogs.claritycon.com/kevinmarshall/2010/12/23/wp7-camera-access-flashlight-augmented-reality-and-barcode-scanning/). But, as of yet, I have been unsuccessful in porting the code to be used by an XNA framework.
Has anyone had any luck either using the Windows Phone 7 camera in an XNA application? If so, care to share your wisdom?
Thanks!
Generally you can access the camera the same way you do it in Silverlight - there is the CameraCaptureTask - you need to add a reference to Microsoft.Phone first and then call it from the game.
Microsoft.Phone.Tasks.CameraCaptureTask task = new Microsoft.Phone.Tasks.CameraCaptureTask();
task.Completed += new EventHandler<Microsoft.Phone.Tasks.PhotoResult>(task_Completed);
task.Show();
That would be for static capture, and your event handler is like this:
void task_Completed(object sender, Microsoft.Phone.Tasks.PhotoResult e)
{
// Do something with e.ChosenPhoto
}
Currently, video recording is done through the undocumented way - this will most likely get your app submission disapproved from the Marketplace, but it is possible nonetheless.
What's done that way is a MP4 file is constantly updated in the IsolatedStorage as the recording is in progress. But then again, there are methods present to include the file in the media library.
Think you are a bit unclear about the whole microsoft and supporting cameras.
Microsoft released not too long ago Expression Encoder 4 which allows you not only to video screen capture your screen but as well access all devices connected to your pc.
I would believe this would be much more ideal then being restrained to only using a windows 7 phone especially for an xna game.
Hope this sheds some light.
Nowadays you can use FileSink to save video from a CaptureSource like VideoCaptureDevice into a file.
http://msdn.microsoft.com/en-us/library/system.windows.media.filesink%28v=vs.96%29.aspx
http://msdn.microsoft.com/en-us/library/system.windows.media.capturesource%28v=vs.96%29.aspx
http://msdn.microsoft.com/en-us/library/system.windows.media.videocapturedevice%28v=vs.96%29.aspx