Please someone help me. I have tried to convert http://drobosson.blogspot.com/2011/01/google-android-camera-preview-data.html and http://marakana.com/forums/android/examples/39.html to Monodroid (C#) and have had no success. I have followed the instructions (as far as I can see) and I do not know how to preview the camera (I am not even on taking a PICTURE yet).
Here is my current code - it fails on the Android.Hardware.Camera.Open() method with a Java.Lang.RuntimeException (Stacktrace says "at Android.Runtime.JNIEnv.CallStaticObjectMethod (IntPtr jclass, IntPtr jmethod) [0x00000] in :0 at Android.Hardware.Camera.Open()...")
I have added the camera permission in the manifest.
Code:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.CameraPage);
_surfaceView = FindViewById<SurfaceView>(Resource.Id.imgCapture);
_debug = FindViewById<TextView>(Resource.Id.lblCameraDebug);
try
{
_camera = Android.Hardware.Camera.Open();
//Android.Hardware.Camera.Parameters camparam = _camera.GetParameters();
//camparam.SetPreviewSize(_surfaceView.Width, _surfaceView.Height);
//_camera.SetParameters(camparam);
//_camera.SetPreviewDisplay(_surfaceView.Holder);
//_camera.StartPreview();
}
catch(Exception ex)
{
_debug.Text = string.Format("Error: {0} - StackTrace: {1}", ex.Message,ex.StackTrace);
}
}
https://github.com/xamarin/monodroid-samples/blob/master/ApiDemo/Graphics/CameraPreview.cs
This clears most of it up. It's a starting point, not a solution.
It does NOT solve:
1. Rotation / Orientation (but that should be in the parameters)
2. Getting it onto a form element using axml (not as an entire page)
3. Taking a picture.
Related
Any idea how to move the Kinect up and down? Theoretically,
sensor.ElevationAngle = 20;
should do the job, but I am getting the following error:
InvalidOperationException
This API has returned an exception from an HRESULT: 0x8007000D
It breaks down even if e.g. reading the current ElevationAngle is the first thing after starting the Kinect Sensor... (the answer to the question here suggests it's because of too much movement operations but it happens even if the Kinect has not adjusted position for some time; if it's duplicating, I am sorry, but I am unable to comment the above mentioned question).
** edit ** code:
using Microsoft.Kinect;
namespace pro02_01_streams.tilt
{
/// <summary>
/// Interaction logic for Tilt_test.xaml
/// </summary>
public partial class Tilt_test : Window
{
private KinectSensor sensor;
public Tilt_test()
{
InitializeComponent();
Test();
}
public void Test(){
if (KinectSensor.KinectSensors.Count == 0)
{
MessageBox.Show("No Kinects presents", "Error");
Application.Current.Shutdown();
}
try
{
sensor = KinectSensor.KinectSensors[0];
sensor.DepthStream.Enable();
sensor.ColorStream.Enable();
sensor.Start();
sensor.ElevationAngle = 1;
}
catch
{
MessageBox.Show("Failed to initialize kinect", "error");
Application.Current.Shutdown();
}
}
}
}
Your code works fine for me. To find out if your Kinect works properly, open the Kinect Developer Toolkit Browser and run the Kinect Explorer-WPF. In the application, go to Sensor Settings and move your Kinect with desired angle.
My code which uses NSKeyedUnarchiver now throws a TypeLoadException when using the latest monomac from Git:
System.EntryPointNotFoundException: monomac_IntPtr_objc_msgSend_IntPtr at at (wrapper managed-to-native) MonoMac.ObjCRuntime.Messaging:monomac_IntPtr_objc_msgSend_IntPtr (intptr,intptr,intptr) at MonoMac.Foundation.NSKeyedUnarchiver..ctor (MonoMac.Foundation.NSData data) [0x0002a] in /Users/richard/Development/MonoMacSources/gitsrc/monomac/src/Foundation/NSKeyedUnarchiver.g.cs:93
The same code runs fine using the version of monomac.dll which ships with Xamarin Studio.
Test case:
public NSTextFieldCell Cell = new NSTextFieldCell("string");
public override void AwakeFromNib()
{
base.AwakeFromNib();
Console.WriteLine(Cell.StringValue);
using(NSMutableData data = new NSMutableData())
{
using(NSKeyedArchiver archiver = new NSKeyedArchiver(data))
{
this.Cell.EncodeTo(archiver);
archiver.FinishEncoding();
}
using(NSKeyedUnarchiver unarchiver = new NSKeyedUnarchiver(data))
{
var cell = (NSTextFieldCell)Activator.CreateInstance(typeof(NSTextFieldCell), new object[] { unarchiver });
unarchiver.FinishDecoding();
Console.WriteLine(cell.StringValue);
}
}
}
Exception is thrown at new NSKeyedUnarchiver(data)).
Does anyone have an idea? Or a workaround?
This is effectively a regression in the latest MonoMac from Git.
I will fix it (currently there is no workaround except use an earlier version from Git).
It's fixed now.
Has anyone heard of any issues with MessageDialog's not displaying on Windows 8 tablets? Or more specifically Samsung 700t? It uses a regular intel process and not ARM. I built the app on a laptop and the messagedialog shows when debugging from the laptop, shows on the tablet simulator but doesn't show on the actual tablet.
I'm using the Caliburn.Micro IResult interface to display the messagedialog in the view.
Heres snippits of code that I'm using:
public IEnumerable<IResult> NavExecute(String method)
{
Windows.UI.ViewManagement.ApplicationView.TryUnsnap();
var conn = NetworkInformation.GetInternetConnectionProfile();
if (conn.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess)
{
yield return new MessageDialogResult("Internet Connection Not Detected", "Connection Error");
netOn = false;
}
}
the above is in my view model base class, and heres the implementation of the IResult class itself:
public class MessageDialogResult : ResultBase
{
private readonly string _content;
private readonly string _title;
public MessageDialogResult(string content, string title)
{
_content = content;
_title = title;
}
public async override void Execute(ActionExecutionContext context)
{
var dialog = new MessageDialog(_content, _title);
await dialog.ShowAsync();
OnCompleted();
}
}
I doub't it's an issue with the code since I'm debugging in x86 mode on both devices (before anyone asks why I'm not debugging for all devices it's because I'm using SQLite which requires a seperate package for each arhitecture.)
I'm not sure if theres a setting somewhere in Windows 8 that disables in app popups, but I couldn't find one.
Any ideas?
Are you handling the callback of Coroutine.Execute?
The callback on Execute might be calling back with an exception thrown by the coroutine - this would silently fail if you weren't explicitly looking for it in the callback
Coroutine.Execute(YourEnumerator(), new ActionExecutionContext { Blah }, (o, e) => {
if(e.Error != null) // Something went wrong
});
Maybe the async await is throwing or something like that (can't think why!)
Edit:
Ah additionally stuff in your enumerator could also throw:
Windows.UI.ViewManagement.ApplicationView.TryUnsnap();
var conn = NetworkInformation.GetInternetConnectionProfile();
Either one could throw making the outer enumerator swallow an exception if not handled in the callback - or could be a nullref on conn?
The reason why GetInternetConnectionProfile() was returning a null ref was due to the fact that when on a laptop, if you disconnect from a wireless connection the laptop's internet connection profile defaults to ethernet, whereas the tablet (at least the Samsung 700T) doesn't have an ethernet port so it's connection profile doesn't exist if a wireless connection isn't established.
Thanks to Charleh for pointing me in the right direction.
I want to play sound from a mp3 file in windows 8 metro-style app. I tried two approaches to do so:
Method1:
This is using the code provided by https://stackoverflow.com/a/10961201/147530. It works.
Method 2:
Here I just new a MediaElement and set its Source property like so:
var x = new MediaElement { Source = new Uri("ms-appx:/Assets/MyMp3File.mp3") };
When I do x.Play() nothing happens however. There are no exceptions thrown.
Question: How can I make method 2 work?
EDIT:
Wanted to update that none of the MediaFailed, MediaOpened, MediaEnded event handlers get called using Method 2.
sound = new MediaElement { Source = new Uri("ms-appx:/Assets/Clook.mp3") };
sound.MediaFailed += sound_MediaFailed;
sound.MediaOpened += sound_MediaOpened;
sound.MediaEnded += sound_MediaEnded;
static void sound_MediaEnded(object sender, RoutedEventArgs e)
{
Debugger.Break();
}
static void sound_MediaOpened(object sender, RoutedEventArgs e)
{
Debugger.Break();
}
static void sound_MediaFailed(object sender, ExceptionRoutedEventArgs e)
{
Debugger.Break();
}
A couple of things to try. Try the following code
var music = new MediaElement()
{
AudioCategory = AudioCategory.ForegroundOnlyMedia,
Source = new Uri(this.BaseUri, "Assets/MyMp3File.mp3")
};
// This is really the only difference, adding it to the visual tree
// LayoutRoot is the root of the visual tree, in the case, a grid in my XAML
LayoutRoot.Children.Add(music);
music.Play();
Adding it to the visual tree may be the key. Put a break point on that to make sure your MediaElement has data in it.
Second (and actually happened to me so, that's why I mention it), I was developing on a Samsung device from //Build that has a docking station. The audio jack on the device and the speakers are disabled when it is in the docking station. You have to plug a headset into the docking station directly or remove it from the docking station to hear any sound.
You have to put the MediaElement in the visualTree before to make it play any media :)
Use x.autoplay = true. With autoplay it will wait until it's loaded.
Newbie here, just trying to create a signal event handler in response to an onclick menu item.
Aint working for me.
I click on the menu item, click signals, to the right of "Activated" where it says "Click to Add Handler", I type in "MyOnClick"
then it shoots me out an error. weird.
Exception has been thrown by the target of an invocation.
I am running this in windows 7 under a vm on macbook pro. Windows is not sharing folders from Macbook Pro so shouldn't be a UNC issue. Pathways seem fine.
Any ideas?
Ben
I have the same issue on mac and windows with current monodevelop versions.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotImplementedException: The method or operation is not implemented.
It's annoying me so much! Must be some bug.
EDIT: I've solve it!
In source add method like this:
protected virtual void onClick (object sender, EventArgs e)
{
MessageDialog md = new MessageDialog (this, DialogFlags.Modal,
MessageType.Error, ButtonsType.Close, "Some error");
md.Response += delegate(object o, ResponseArgs args) {
if (args.ResponseId == ResponseType.Close)
Console.WriteLine ("Response: Closed");
else
Console.WriteLine ("Other response happened.");
};
md.Run ();
md.Destroy ();
}
Then switch to visual designer and instead double click on signal/method name just type in method name [this case] onClick (no brackets). This time a method is implemented and doesn't cause throwing error.
It work but is not as comfortable as double click.