I do have a Xamarin Forms project where I want Android, iOS and WinPhone as targets. (Right now I only look at Android.)
I am having trouble playing Audio and think I will need to implement it differently on each device.
I started with adding this code in the app.cs of the shared project
#if __ANDROID__
MediaPlayer _player;
_player = MediaPlayer.Create(this, Resources.Raw.bear); // "Resources.Raw.bear");
_player.Start();
#endif
but found that I cannot really reference the bear.wav, so I think I have to add the bear.wav for each project/platform and also handle the playing code separately. (See also http://developer.xamarin.com/recipes/android/media/audio/play_audio/ )
Unfortunately, I could not find a sample - or any documentation - on how to do this.
http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/ is the closest I could find, but it seems to be highly focused on renderers.
What I thought I would do would be to define an abstract class in the shared project (some simple class, just with a void play method), and use it, and have the specific implementations in each platform-project. How to go about this?
It looks like
Write device platform specific code in Xamarin.Forms
answers the question - which is not so much a Xamarin Forms question as a Visual Studio shared project question and can be solved by creating an interface/abstract class and then implementing that for each platform and injecting the implementation.
Related
I'm totally new in xamarin.
I'm trying to use CoreNFC in my xamarin.forms multiplatform app.
But I don't know how to do it because i can only import CoreNfc in myapp.ios and not in myapp.
There is someone that know how to do it ?
Thanks in advance!
Core NFC belongs to the iOS Framework, so you can import and use it only in our iOS Project.
You could implement the NFC feature on each platform you want to support and use a interface and the Xamarin Dependency Service, to have access to these platform specific implementations in your shared code.
Or you look around for a plugin which did this work for you. A starting point could be NFCForms from poz1. But if I remember well it has so far only support for Android and Windows Phone.
Good time of day to all. I am working on Xamarin.Forms project, including iOS, Android and UWP parts. My project requires usage of different custom fonts, accessible for all devices. So I added custom fonts and I am selecting them with
string fontName = Device.OnPlatform(
"RoundedLEDBoard-7",
"rounded_led_board-7.ttf#Rounded LED Board-7",
#"Assets\Fonts\rounded_led_board-7.ttf#Rounded LED Board-7");
Font names and locations are correct.
On the modeling stage I used a single page solution, to prototype some of the basic functionality. All worked exactly as expected on all three platforms, both emulators and real test devices. However, after adding navigation capabilities and changing App.xaml.cs from
MainPage = new Different_fonts.MainPage();
to
MainPage = new NavigationPage(new Different_fonts.MainPage());
I have discovered, that the font is not loaded (or displayed?) in UWP part of the project. Android and iOS parts look as expected. Complete re-build of the entire solution did not help. Does any one know where the problem is and what is the cure remedy?
It looks like you found quite an odd bug! I am also seeing this issue with a sample project using Forms 2.3.3. As you mentioned, iOS and Android don't experience this issue so this should work on UWP as well.
Unfortunately I don't have a workaround for this in the meantime, but I've filed a bug report so we can look into this.
I'm trying to use this method:
https://developer.xamarin.com/api/member/System.Type.GetInterfaces()/
like this:
public MainPage(Type type) {
if (type.GetInterfaces().contains("Form")) {
// go on
But my Xamarin Studio does not recognize the GetInterfaces method, why?
It sounds like you are using a PCL Xamarin Forms project. I suggest you read more about that here or watch some of the helpful videos around the internet (like this one, which talks about different PCL Profiles) but basically and PCL project attempts to allow many of the common APIs available on all platforms. This means that if a certain platform does not support GetInterfaces() or if the Forms team has not implemented that API yet, it will not be available to your from the Forms project.
The nice thing about Xamarin Forms is that you can still access all native APIs if you need to. To do this you would create an interface and use Xamarin Forms Dependency Service (link) which would probably allow you to access that API from your Forms project.
If you need an example of how to do that, just let me know.
We want to create an app, which works on multiple platforms showing a lot of lines and graphics. Since we have a Xamarin license and this app will not require any native look Xamarin.Forms is our choice. On the other hand we need mentioned graphics so we are thinking about using MonoGame (since we already know this framework). The only thing in here is, we would like to use some scrollviews in overlays and maybe the appbar (navigation bar on top). For this we had some problems in our test.
Now we are unsure what to use and would like to know if there are any other approaches to use Xamarin.Forms and OpenGL in parts.
Xamarin.Forms has a OpenGLView View and it can be used within a Xamarin.Forms page amongst other controls.
There is some examples, using Xamarin.Forms with this here.
Do note, however that this is only available in iOS and Android however.
Along with MonoGame, you have Urho which is mentioned on the Xamarin website that you may want to look into, link here. As to whether Urho is compatible with Xamarin.Forms I do not know.
I'm building a shared project and I want to access the camera. For now i'm just trying to get this to work on android.
I found this here in stackoverflow and it works but I'm not being able to put this to work in my project becouse I want to call the camera in a ContentPage and not in my Class App : Application.
I would recommend this library for that: http://components.xamarin.com/view/xamarin.mobile