Forum Xamarin.Forms

How to use XLabs.MediaPicker control?

ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

Following the Description for XLabs Camera, I created a project and created the CameraViewModel and CameraPage. But running the solution it just displays the 3 buttons but clicking the buttons does nothing. It appears I am missing something, as the Setup() method is never called.

On searching this forum found some threads but what is said in there is not clear. So what am I missing?

Normally we initialize the view model in the master page. But I don't see any such statement in the CameraPage.xaml.cs. Few threads suggested initializing a Renderer but the given code is confusing.

So how do I make this working?

Answers

  • PaulDistonPaulDiston USUniversity ✭✭✭✭
    edited February 2015

    Hi,

    There were a few things missing which stopped it from working such as setting the Resolver and hooking up the BindingContext, so I have packaged up the sample into the following (Android only) :-

    smartmobiledevice.co.uk/Samples/Xamarin/MediaPickerSample.zip

    There is a limit to the size of photo that can be shown with the following error appearing in the output window :-

    Bitmap too large to be uploaded into a texture (4208x3120, max=4096x4096)

    Hope this helps.

    Paul Diston

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @PaulDiston It appears your sample solution is bit old. So it is not building with latest updates to XS, XF & XLabs.

    Also I see you setting the BindingContext in the CameraPage() constructor. But I couldn't find any code on setting the Resolver. Can you guide me on this.

    Also @SKall may also have something to comment on this issue as he updated the XLabs recently.

  • PaulDistonPaulDiston USUniversity ✭✭✭✭
    edited February 2015

    Hi,

    @ShantimohanElchuri I have just opened the solution Xamarin Studio (I had originally developed the sample in Visual Studio), I updated the references, built the application and deployed and everything worked successfully.

    Would you be able to explain in a little more detail what you are experiencing?

    Regarding the Resolver, you should see in the MainActivity.cs of the Android project, the following, which sets up the Resolver :-

    var container = new SimpleContainer(); container.Register<IDevice>(t => AndroidDevice.CurrentDevice); container.Register<IDisplay>(t => t.Resolve<IDevice>().Display); container.Register<INetwork>(t => t.Resolve<IDevice>().Network); Resolver.SetResolver(container.GetResolver());

    Does this help?

    Thanks

    Paul Diston

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @PaulDiston More on running your sample project. I tried on Windows Phone, both device and emulator.

    1. In 'Debug' mode, on both device and emulator, it doesn't even deploy giving the error asking to unlock the device and check if the program is loaded.
    2. In 'Release' mode, on device it deploys to device but errors out on loading symbols. Also indicates it has got some 'Just My Code' enabled. I don't about this.
    3. In 'Release' mode, on the emulator it errors out with exception "IResolver has not been set....".
  • PaulDistonPaulDiston USUniversity ✭✭✭✭

    Hi,

    @ShantimohanElchuri I wasn't sure which platform you were running on, so unfortunately the sample was only coded for Android.

    Out of interest, if you are running on Xamarin Studio, how are you getting the Windows Phone project to deploy, I see an error "This Project Type not supported by Xamarin Studio".

    Thanks

    Paul Diston

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @PaulDiston Sorry, I didn't mention the config. I was running in VS2013 on a Windows 8.1 machine.

    Since, Xamarin Studio on my Windows laptop is screwed (see my unanswered thread https://forums.xamarin.com/discussion/32346/install-android-support-library-available-in-sdk-installer-error-doesnt-leave-us#latest), I use MacBook Pro for my Android testing which is at home right now. So I will check it out when I return home after work.

    Also I posted my previous post before my browser reported your answer. So I will try all these when I get back home.

  • SKallSKall USMember ✭✭✭✭

    You might want to download the latest code: https://github.com/XLabs/Xamarin-Forms-Labs/archive/master.zip

    Run the sample project from there.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @PaulDiston Good, it works fine on Android. But it seems you made it with old XLabs version. I will check it with the new XLabs version.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @PaulDiston Yes, I created a separate project for the MediaPicker with new XF and XLabs versions. Just by changing the 'usings', I was able to make it work in Android.

    The only difference between your code and the sample by SKall is setting BindingContext in CameraPage.xaml.cs to 'new CameraViewModel()'. Since @SKall sample also works, he also must be setting the BindingContext somewhere but I have to dig in and see.

    And @SKall, your sample on github works in Android and I am yet to run in WP, the other env that I work on.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @SKall Running the XLabs sample's WP project is giving the following error:

    Could not find file 'C:\Users... ... ...\Samples\Xamarin-Forms-Labs-master\Samples\XLabs.Sample.WP\obj\x86\Debug\XapCacheFile.xml'. Please rebuild the solution and try again.

    Rebuilding the solution, as suggested, doesn't remove this error. Is this file suppose to be in the .zip.

    Any tips?

  • SKallSKall USMember ✭✭✭✭
    edited February 2015

    Are you building x86 or ARM version? Did you delete both obj and bin folders before rebuilding?

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @SKall It was in 'Mixed Platforms'. Building for X86 worked. Also when I tried for 'Any CPU' it complained that SQL Lite will not work for it.

    @PaulDiston I tried to make your sample work in WP also. But you are using XLabs v1.2 and your WP project is not preloaded with it as you were concentrating on Android only. But I created another project in which following your def of Resolver, I was able to run successfully in both Windows Phone and Android. Soon I will make it available here so that someone can test it in iOS.

    @SKall I am just trying to separate just MediaPicker part from your sample. Nothing special is done. That separation will help me to understand its working. My iOS simulator is not working properly. I know it works there. Just I have to understand how it works as Android and iOS dev is new for me.

  • SKallSKall USMember ✭✭✭✭
    edited February 2015

    Yep, for WP only x86 and ARM work as build targets. For the mediapicker you would probably first take out the camera view model:

    https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/Samples/XLabs.Sample/ViewModel/CameraViewModel.cs

    If you have set resolver to register IMediaPicker you can then simplify these lines to just use Resolver.Resolve< IMediaPicker >:

    https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/Samples/XLabs.Sample/ViewModel/CameraViewModel.cs#L163-L166

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @SKall Is XLabs updated for XF 1.3.5?

  • SKallSKall USMember ✭✭✭✭

    Yes, just pushed in release for 1.3.5 yesterday and working on pre-release for 1.4.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @SKall Somewhere you posted that we should load XLabs 2.0.5539 to work with XF 1.3.5. When I updated the NuGet packages on my Mac, it updated XLabs to 2.0.5540 and there was no problem in running my Android project.

    But when I updated NuGet packages in VS for my WP project, it also updated to 2.0.5540. But building the WP project is complaining about XF 1.4. I don't find any way to get XLabs 2.0.5539. How do I resolve this?

  • SKallSKall USMember ✭✭✭✭

    It was my mistake that I just discovered an hour ago. If you don't mind working with 1.4.0-pre1 you can update the Forms NuGet package to 1.4.0-pre1 (just for WP8) or update XLabs to the pre-release. I will create a new release tonight with correct build versions on the WP side.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @SKall I prefer working with stable versions. So I will wait for the new release of XLabs.

    Just interested to know which time zone you are in...I see you responding quickly any time (I'm in ET).

  • SKallSKall USMember ✭✭✭✭

    EST (Tampa, FL)

  • kcswindowskcswindows USMember

    Xlabs IMediapIcker Service not Working...

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @kcswindows I think the XLabs is not being updated. Either you clone the project and troubleshoot yourself or use Xamarin's Media plugin if you just want to select a photo or video or use camera.

Sign In or Register to comment.