I am building a Windows Phone app which uses the camera. I have the code:
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) ||
(PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) == true)) {
// Initialize the default camera.
_photoCamera = new Microsoft.Devices.PhotoCamera();
//Event is fired when the PhotoCamera object has been initialized
_photoCamera.Initialized += new EventHandler<Microsoft.Devices.CameraOperationCompletedEventArgs>(OnPhotoCameraInitialized);
//Set the VideoBrush source to the camera
viewfinderBrush.SetSource(_photoCamera);
}
else {
// The camera is not supported on the device.
this.Dispatcher.BeginInvoke(delegate() {
// Write message.
txtDebug.Text = "A Camera is not available on this device.";
});
}
}
private void OnPhotoCameraInitialized(object sender, CameraOperationCompletedEventArgs e) {
int width = Convert.ToInt32(_photoCamera.PreviewResolution.Width);
int height = Convert.ToInt32(_photoCamera.PreviewResolution.Height);
}
And I keep getting the exception:
"Access to camera requires the ISV Camera Capability."
I have a Lumia 900, and I know it runs camera APIs (the sample form MS works fine). But when I go to put this code in my app, I get this exception. Does anyone have any idea what might be going on? I am a good C#'er, but the Windows Phone is quite new to me.
Many thanks!
Brett
Solved it:
I had to add the line:
<Capability Name="ID_CAP_ISV_CAMERA"/>
to my WMAppManifent.xml file.
Related
I've got a little problem with ZXing.net... I dosen't work !
Maybe I use it incorrectly, but I search, search, search, nothing seems to work... I use WindowsForms. I want to read my QR Code thought my camera. I use another library called AForge. This one works perfectly ; My camera shows up and works like a charm ! But when I want to read a QR Code, it dosen't work...
So maybe someone will be able to help me ... ?
//When I load my form, I start the camera
private void FrmConnexion_Load(object sender, EventArgs e)
{
// enumerate video devices
videoSources = new FilterInfoCollection(FilterCategory.VideoInputDevice);
// create video source
videoStream = new VideoCaptureDevice(videoSources[0].MonikerString);
// set NewFrame event handler
videoStream.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
// start the video source
videoStream.Start();
}
//Every new frame of the video
void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
try
{
streamBitmap = (Bitmap)eventArgs.Frame.Clone();
safeTempstreamBitmap = (Bitmap)streamBitmap.Clone();
Pic_Camera.Image = streamBitmap;
Pic_Camera.Refresh();
//Where I decome my QR Code.
Result result = barcodeReader.Decode(streamBitmap);
//To see my result, I register my result into a Label.
Lbl_Identifiant.Text = "{result?.Text}";
}
catch (Exception exp)
{
Console.Write(exp.Message);
}
}
I think I didn't forget anything..
Thanks for your help !
I have created a MediaElement in my Windows Phone 8.1 app, and I am trying to play an mp4 video. When I press the button to play the video, it shows the video's first frame (splash screen), but it never goes beyond that, and it looks like a still picture. What could I be doing wrong? I don't get any error from my MediaFailed method, either.
private void openButton_Click(object sender, RoutedEventArgs e)
{
shakeImage.Visibility = Visibility.Collapsed;
timer.Stop();
timerReset.Stop();
rotateImage.Stop();
mediaElement.Stop();
Uri explosion = new Uri(BaseUri, "Explode.mp4");
mediaElement.Source = explosion;
mediaElement.Play();
mediaElement.MediaFailed += mediaElement_MediaFailed;
}
void mediaElement_MediaFailed)object sender, ExceptionRoutedEventArgs e)
{
throw new FileNotFoundException();
}
if you are playing audio file from your phone you should change "UriKind " to "Relative" like this
Uri explosion = new Uri( "Explode.mp4",UriKind.RelativeOrAbsolute);
// or you could use this way
Stream stream = isoStore1.OpenFile("Explode.mp4", System.IO.FileMode.Open, System.IO.FileAccess.Read );
this.mediaElement.Stop();
this.mediaElement.SetSource(stream);
mediaElement.Play();
stream.Close();
Turns out it was due to Windows Phone 8 being picky about file formats and not throwing errors even though they were incorrect. I converted it to a certain wmv type and it seems to work now.
I am developing one of my android app in xamarin platform in which i want to play audio using url and now i am able to play that file using url. So now i want perform following tasks where got stuck.
1) play file with seek bar according to file buffer size .
2) Unable to implement media player listener like OnComplitionListener specially in Xamarin.
Here i want share code that only playing audio without seekbar and media player listeners.
public void OnlinePlayer(String filePath)
{
try {
player.Reset ();
player.SetDataSource(filePath);
player.SetAudioStreamType(Stream.Music);
// player.SetOnCompletionListener(this);
player.Prepare();
player.Start();
player.PrepareAsync();
player.Completion += delegate {
};
} catch (Exception e) {
Console.WriteLine("OnlinePlayer()", "Exception in streaming mediaplayer e = " , e.Message.ToString());
}
}
In my case, I resolve the 2nd part of your question in this way for the listener:
player.Completion += OnPlayer_Completion;
then
private void OnPlayer_Completion(object sender, EventArgs e)
{
...your code...
}
In my App you can open a Site where you can switch on and off the Flashlight.
The first time it works, but if I try to switch the flashlight on a second time the App crashes.
I think this is a Problem with AudioVideoCaptureDevice.OpenAsync. If I call it a second time the App crashes with a System.Reflection.TargetInvocationException WinRT-Informationen: Unable to acquire the camera. You can only use this class while in the foreground.
Someone know this Problem?
protected AudioVideoCaptureDevice Device { get; set; }
public Page10()
{
InitializeComponent();
}
async void tglSwitch_Checked(object sender, RoutedEventArgs e)
{
var sensorLocation = CameraSensorLocation.Back;
if (this.Device == null)
{
// get the AudioVideoCaptureDevice
this.Device = await AudioVideoCaptureDevice.OpenAsync(sensorLocation,
AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation).First());
}
var supportedCameraModes = AudioVideoCaptureDevice
.GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode);
if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
{
this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
// set flash power to maxinum
this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower,
AudioVideoCaptureDevice.GetSupportedPropertyRange(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max);
this.tglSwitch.Content = "Light on";
this.tglSwitch.SwitchForeground = new SolidColorBrush(Colors.Green);
}
}
void tglSwitch_Unchecked(object sender, RoutedEventArgs e)
{
var sensorLocation = CameraSensorLocation.Back;
sensorLocation = CameraSensorLocation.Back;
var supportedCameraModes = AudioVideoCaptureDevice
.GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode);
if (this.Device != null && supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.Off))
{
this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
this.tglSwitch.Content = "Light off";
}
}
I would recommend to initialize the camera with OpenAsync ONE TIME in page lifecycle, for example in OnNavigatedTo event. And only makeSetProperty() methods calls code in your checkbox events to control light. It is also very important to dispose camera correctly then leaving the page, for example in OnNavigatedFrom event, by calling device.Dispose(). This option also make your flashlight to work faster.
Keep in mind that Windows Phone 8.1 now has dedicated API for torch, which works great and the code is more beautiful. You can use in Silverlight project as well, but you have to migrate your project. Here is more about this http://developer.nokia.com/community/wiki/Using_the_camera_light_in_Windows_Phone_7,_8_and_8.1 and https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.devices.torchcontrol.
I an new in emgu cv c#. I want to create a camera only for simple photocapture from my laptop camera and other camera device connected to my laptop.I dont want video capture only simple photo capture.with one start and one capture button.and will save in particular location.helped would be appreciable.
namespace camera
{
public partial class cameracaps : Form
{
Capture capturecam=null;
bool capturingprocess=false;
Image<Bgr,Byte>imgOrg;
Image<Gray,Byte>imgproc;
public cameracaps()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
Capture cam = new Capture();
}
catch (NullReferenceException exception)
{
MessageBox.Show(exception.Message);
return;
}
Application.Idle += new EventHandler(processFunction);
capturingprocess=true;
}
void processFunction(object sender,EventArgs e)
{
imgOrg=capturecam.QueryFrame();
if(imgOrg ==null)return;
imgproc=imgOrg.InRange(new Bgr(50,50,50),new Bgr(250,250,250));
imgproc = imgproc.SmoothGaussian(9);
original.Image=imgOrg;
processed.Image=imgproc;
}
private void Button1_Click(object sender, EventArgs e)
{
if(capturingprocess==true)
{
Application.Idle-=processFunction;
capturingprocess = false;
Button1.Text="play";
}
else
{
Application.Idle+= processFunction;
capturingprocess= true;
Button1.Text="pause";
}
}
}
}
showing..The type initializer for 'Emgu.CV.CvInvoke' threw an exception. error..indicating error in
Capture cam = new Capture();
help me.
This is one of the biggest problem almost all the time we face in emgu cv.First of all copy dll file name opencv_core290.dll,open_cvhighgui290.dll to your project bin,try to use dependency tracker for dll files.Install dependency from this link-http://www.emgu.com/wiki/index.php/Download_And_Installation..If its not work then you should understand that application is getting connection with camera.Then go to My computer->right click->property->advanced system setting->system property->advance->environment variables->system variables->path->edit->and paste C:\Emgu\emgucv-windows-universal-cuda 2.9.0.1922\bin.and press ok.restart your system and it will work.