Xamarin.Media.MediaPicker

Introducing MediaPicker

With the latest release of the Xamarin Mobile API Preview, in addition to improving the Contacts APIs, we added a new API: MediaPicker. The MediaPicker API provides a common API on iOS, Android, and Windows Phone for taking photos and videos, or selecting them from the media gallery.

It’s a very simple API to use. For example, the following Android code opens the native Android photo browser, allows the user to pick a photo, and then shows that photo in an ImageView:

ImageView image = FindViewById<ImageView> (Resource.Id.image);
var picker = new MediaPicker (this);
picker.PickPhotoAsync()
      .ContinueWith (t =>
      {
            if (t.IsCanceled || t.IsFaulted) // user canceled or error
                  return;
            Bitmap b = BitmapFactory.DecodeFile (t.Result.Path);
            RunOnUiThread (() => image.SetImageBitmap (b));
      });

The beauty of this API is that the PickPhotoAsync method is available on all three platforms, and works the same way everywhere, though of course the media picker UI looks different on each platform:

Android Photo Picker

iOS Photo PickerWindows Phone Photo Picker

Additionally, we have included programmatic feature detection to allow you to determine at runtime what media types are supported via the MediaPicker.PhotosSupported and MediaPicker.VideosSupported Properties. This is especially important for Windows Phone 7, which doesn’t support video in their gallery picker.

Taking Photos or Video

In addition to MediaPicker, we’ve also made it simpler to get access to media file names by allowing you to specify their directory and file name; if you don’t specify a directory, the API will let you know the location to which they were saved.

Furthermore, the API allows you to specify which camera to use, the quality of the video to take, and more, through hint options. You can even query the API to determine what cameras are available:

if (!picker.IsCameraAvailable)
      return;
VideoView videoView  = FindViewById<VideoView> (Resource.Id.video);
picker.TakeVideoAsync (new StoreVideoOptions
{
      Directory = "Xamovies",
      DefaultCamera = CameraDevice.Front,
      DesiredLength = TimeSpan.FromMinutes (5)
})
.ContinueWith (t =>
{
      if (t.IsCanceled || t.IsFaulted) // user canceled or error
            return;
      videoView.SetVideoPath (t.Result.Path);
});

Fully C# TPL Compatible

And the best part of all this is that the APIs are all asynchronous and built on the C# Task Parallelism Library. This allows you to use the Task.ContinueWith method so that the UI Thread isn’t blocked, and reports user cancellation via IsCanceled and error conditions via the IsFaulted and/or Exception properties.

So download the preview and give it a whirl today!

What’s next?

If you want to influence what cross-platform APIs we create next, feel free to check out our Xamarin Mobile API UserVoice page, where you can vote on features or submit your own ideas.

Update on Xcode 4.3 support

Yesterday evening, we released MonoTouch 5.2.5 and MonoDevelop 2.8.6.5 with support for Xcode 4.3 to our beta channel. This enables you to have Xcode 4.3 installed in the Applications folder and continue to use MonoTouch.

Since Xcode 4.3 takes with it a few command line tools and relocates them, MonoTouch 5.2.5 and MonoDevelop 2.8.6.5 are reconfigured to pick up these new locations so you can be up and running again as quickly as possible.

Removing Old Xcode
It’s important to note that installing Xcode 4.3 will ask you if you want to delete your existing installations of Xcode (taking with it the /Developer folder). What you may not know is that MonoTouch and Mono for Android (for Mac) get installed into this folder too. If you choose to remove Xcode 4.2, you will need re-install MonoTouch and/or Mono for Android. Alternatively, you can keep your existing Xcode 4.2 installation and things will continue to work as expected.

Please let us know if you run into any problems with this release. If you do run into problems, feel free to e-mail us at support@xamarin.com

Xcode 4.3 support

Today, Apple released Xcode 4.3 and we want to give some guidance to MonoTouch and Mono for Android developers using a Mac.

While we can’t disclose pre-release information, nor do we know when the actual releases will happen, we are always tracking new Xcode releases. Upon each new update, we need to test the officially released version before issuing our own update – a process that takes a few hours/days depending on how large the changes are between the last preview and the actual release.

Support for Xcode 4.3 will be available later today as an update to MonoTouch and MonoDevelop. Until these packages are out, we advise MonoTouch developers not to install Xcode 4.3.

Introducing Xamarin.Contacts

Xamarin Contacts API

Our goal at Xamarin is to make cross-platform mobile development as easy as possible. As part of that we’ve created Xamarin.Mobile, a library that runs on iOS, Android and Windows Phone 7 and abstracts commonly-used APIs to reduce developer effort in supporting multiple platforms.

Sometimes, when developing a new abstract API, we have the opportunity to design an API more elegant and beautiful than anything offered by the underlying platforms. In the last couple of weeks, we created a new addressbook API that we think you will love using.

The following sample shows how to query the address book for people’s whose last name is “Smith” and extract some common fields:

var book = new AddressBook (this) {
    PreferContactAggregation = true
};
foreach (Contact c in book.Where (c => c.LastName == "Smith")) {
    print (c.DisplayName);
    foreach (Phone p in c.Phones)
        print ("Phone: " + p.Number);
    foreach (Email e in c.Emails)
        print ("Email: " + e.Address);
}

As you can see, the query is expressed in a simple LINQ statement which works efficiently across all three major platforms, and the code is succinct and readable.

You will also notice that we expose some simple properties for each Contact (DisplayName, Emails, Phones). These properties are available on all platforms. See the API documentation for a complete list.

Comparison to Android and iOS APIs

It’s interesting to compare the code snippet above with both the Android/Java version and the equivalent iOS/Objective-C version.

In the case of the native Android APIs, you will notice that Android requires developer to use an ad-hoc query system based on passing arrays with special keys and iterating over a ContentResolver. Writing and debugging these statements is not a lot of fun. We think everyone will agree our API is a lot friendlier.

On iOS API is a little simpler as it does not use a query system, and instead you must express the intent with more code and do more bookkeeping.

The Magic Behind Xamarin.Contacts

If you look closely, the Addressbook class implements the IQueryable interface which is the gateway to turn C# expressions into fine-tuned queries for the underlying Android query system, the iOS addresbook APIs, or the contacts on Windows Phone 7.

The magic of Xamarin.Contacts is that it maps to the most efficient implementation on each platform, wheverever possible. On Android in particular, searching for a contact is as fast as using the native ContentResolver system — but much simpler. You can use Where, Select, Count, Skip, Take, Any, First, Single, OrderBy and OrderByDescending operations knowing that Xamarin.Contacts will transform these into native query elements. For any other operations, we gracefully degrade to LINQ to Objects.

On iOS and on Windows Phone, we convert to objects and run LINQ to Objects.

Availability

You can start using Xamarin.Contacts today to simplify your app. Download it from the Xamarin.Mobile web page, and be sure to check out the API documentation for more details.

Latest Xamarin.Mobile API Preview: Camera, Improved Contacts, and…Windows Phone 7!

We are pleased to announce that we have released a new preview of Xamarin.Mobile, our unified cross-platform API for accessing the device’s addressbook, GPS, camera and photo album.

This release includes two major new features. First, we have extended Xamarin.Mobile beyond iOS and Android, to support Windows Phone as well. Second, we have introduced the MediaPicker class, which can be used to access both the Camera and photo album in a cross-platform manner. MediaPicker supports both photos and video.

Additionally, this release includes several enhancements to the already-released Contacts API, including performance improvements on Android and various bug fixes.

Expect some additional blog post over the next few days that will go over the details of these new features. In the meantime, check it out!

Top 5 Features of Ice Cream Sandwich

Back in December 2011, Mono for Android 4.0 was released and with this release came support for the latest APIs for the new Android OS – Ice Cream Sandwich. The Xamarin documentation team did a great job of getting a Introduction to Ice Cream Sandwich document out of the door for this big release.

To help support this and to show how to use some of this functionality, our Xamarin Seminar on 9th February focused on this topic and showed the top 5 APIs (from our point of view) included in the Mono for Android 4.0 release, these five topics are;

  • CalendarAPI
  • ShareActionProvider
  • ActionBarTabs
  • TextureView
  • AndroidBeam

As with all of the seminars, we have put this up on YouTube to watch or you can view it below;

As before, you can view the slides below;



And the code is up on GitHub for you to download and run on your Ice Cream Sandwich emulator or device – https://github.com/xamarin/Seminars/tree/master/2012-02-09-Top5FeaturesOfICS.

We’re still working on the details for our March Seminars so keep an eye out on the blog for an announcement on those and don’t forget it’s not too late to sign up to see James Clancey talk about Third Party Libraries in MonoTouch and Mono for Android on Thursday 23rd February, you can register here: http://bit.ly/xam-feb-seminars

Look forward to seeing everyone at the next seminar,

ChrisNTR

Easily create iOS user interfaces with MonoTouch.Dialog

Just two days ago, we launched MonoTouch 5.2, featuring a memory profiler, unit testing framework, and a new generational garbage collector. With this release we also bundled a popular library called MonoTouch.Dialog; so it’s as easy as adding a new reference to the library to include it into your project.

MonoTouch.Dialog makes building native user interfaces in iOS incredibly easy. But how do you actually use it? Mike Bluestein, who you might recognize from our Xamarin Seminars, has created a 15 minute introduction on MonoTouch.Dialog to get you started.

Important: To view this video in HD, open it up in YouTube or select 720p in the video above.

Using MonoTouch.Dialog allows applications to be created with rich, table-based user interfaces, without all the complexities associated with creating such interfaces manually. At the same time, MonoTouch.Dialog doesn’t limit the ability to customize such applications. This video introduces MonoTouch.Dialog by way of an example that demonstrates how to create a master- detail style of application. It shows how to use MonoTouch.Dialog to present hierarchies of information and use it to create table based user interfaces automatically.

For additional information be sure to check out our MonoTouch.Dialog tutorial.

MonoTouch 5.2 is Here!

Build Great iOS Apps in C#

We’re very proud to announce the availability of MonoTouch 5.2. This release represents months of improvements, with over 300 new features, bugfixes, and enhancements. This is without question the best release of MonoTouch to date.

Here’s a quick rundown of some of the new features in MonoTouch 5.2.

Faster and easier creation of iPhone/iPad Dialogs

MonoTouch.Dialog is a new API that allows developers to create HIG-compliant native iOS screens and dialog boxes and to show table-based information easily. It removes the burden of creating callbacks, data sources and delegate implementation to render tables. MonoTouch.Dialog comes with a range of custom cell renderers that vastly reduce the time it takes to build complex screens and you can even create user interfaces dynamically on demand from JSON data served up online! You can learn more in our MonoTouch.Dialog tutorial and you can also browse the online API documentation.

Memory Profiler

The new MonoTouch memory profiler enables you to identify memory usage hotspots and fix them quickly, tracking the memory usage of managed objects, showing which objects are still referenced, and who is referencing them.

New Garbage Collection Engine

This version of MonoTouch also includes Mono’s new generational garbage collector. You can opt into this new garbage collector by selecting “SGen” as one of the options in your build settings. For certain apps, this can lead to lower memory usage and better performance.

On-device unit testing

Ensure that your app is ready to release with our built-in unit testing framework for running unit tests on both the iOS simulator and your device. You can run your tests manually, or automate them with Instruments. Check out our tutorial on writing unit tests for MonoTouch for more information.

New Libraries

From Mono, we brought the System.Numerics library that brings the Complex and Big Integer data types as well as support for Memory Mapped IO.

But wait, there’s more…

MonoTouch 5.2 also includes more than 300 customer requested enhancements that make it easier to develop great iOS applications. See a full listing of new features and capabilities here.

MonoTouch 5.2 is available immediately to all MonoTouch customers currently within their annual subscription period; just run MonoDevelop and select the Check for Updates menu item.

For complete product information about MonoTouch, and to download a free trial, visit http://xamarin.com/monotouch.

To see example apps built with Xamarin technology, visit: http://xamarin.com/apps.

First seminar is up on YouTube!

Thanks for everyone who joined us for the first Xamarin Seminar, I hope you enjoyed watching it as much as we enjoyed talking about CoreGraphics. The first Xamarin Seminar is over and done with, but it doesn’t stop there! Sign up for our February Seminars where we will be covering these topics on the following dates;

  • Top 5 features of Ice Cream Sandwich with Mono for Android 4.0 with Mike Bluestein – Thursday 9th February 2012 at 11am EST
  • Third party libraries in MonoTouch and Mono for Android with James Clancey – Thursday 23rd February 2012 at 11am EST

Register for both at http://bit.ly/xam-feb-seminars

As promised, we uploaded the “Getting Started with CoreGraphics” seminar that Mike Bluestein presented to us, you can watch this below or watch the video on our YouTube channel – http://youtube.com/xamarinhq
CoreGraphics Xaminar
We also put the slides up on SlideShare for your viewing pleasure;



The code that was shown in two of the samples during the presentation are up on our GitHub account: https://github.com/xamarin/Seminars/tree/master/2012-01-26-CoreGraphics

We are excited to see you at the next seminar on the 9th Feburary and don’t forget to give us your feedback on any of the Xamarin Seminars we create – http://bit.ly/xam-feedback

Chris Hardy

Introducing the Xamarin Seminars

Xaminar Logo

This week will see our first Xamarin Seminar (or what we sometimes like to call a “Xaminar”).

The Xamarin Seminars will be online presentations, every two weeks, to learn about cool things you can do with MonoTouch and Mono for Android.  Each session will feature a short, 20-30 minute presentation from a Xamarin engineer, or a member of our community, followed by a live Q&A session where you can get your questions answered. If you can’t make the live presentation, everything will be archived on YouTube.

The first seminar is Getting Started with CoreGraphics, presented by Mike Bluestein.  Mike has been an active member of the community since MonoTouch launched, and recently joined Xamarin’s excellent documentation team. He’ll show you how to get to grips with creating 2D graphics and modify PDF files on the fly within your MonoTouch applications.

The session will be happening on Thursday 26th January 2012 at 11am EST (4pm UTC).  If you attend live, bring your questions to the short Q&A at the end, if you can’t make it, don’t worry – Xaminars will be recorded and uploaded onto our YouTube channel - http://youtube.com/XamarinHQ

Register via GoToWebinar (you can even join us on your iPhone, iPad or Android phone with their GoToMeeting app) for the first Xaminar from this URL here: https://www3.gotomeeting.com/register/468191934

We have a couple of additional sessions planned as well, so mark your calendars:

  • Thursday 9th February 2012 at 11am EST – Top 5 features of Ice Cream Sandwich with Mono for Android 4.0 with Mike Bluestein
  • Thursday 23rd February 2012 at 11am EST - Third party libraries in MonoTouch and Mono for Android with James Clancey

And in other news… Tweet! Tweet!

We’ve updated our Twitter address to @xamarinhq.  Make sure you follow us!   Of course, we’ll be tweeting out before Xamarin Seminars to make sure you don’t miss them.  And following @xamarinhq is a great way to stay up to date on the newest news about new features for MonoTouch and Mono for Android.  We have some news there, too.  Stay tuned!

Chris Hardy