1

I was playing with Xamarin Mobile api MediaPicker which uses MediaRecorder with monodroid to make a plugin to record a video.

Android must preview the video inside a VideoView. This restriction applies to wp7 and ios too for privacy.

So, I need to get the VideoView (or Rectangle in wp7) from my custom view and setPreviewDisplay to this VideoView in my plugin (or init MediaPicker with this VideoView).

What is the best way to implement my portable plugin which requires UI element ?

Thanks in advance for your help.

Alphapage
  • 901
  • 1
  • 6
  • 29

1 Answers1

1

What is the best way to implement my portable plugin which requires UI element ?

I guess my first question is "do you need a portable plugin?"

What is the interface that you actually need at the ViewModel layer or lower?

My guess is that the cross-platform interface that the ViewModel will see might contain just:

  • some control commands (things like start/stop)
  • some summary information - e.g. video length
  • a file access layer - this may be as little as a file path?

If that's the case, then I'd probably implement most of the logic within Controls/Views/UIViews in the UIs, and would then bind the relevant commands and values to those ViewModel properties.

So I wouldn't personally implement this as a plugin at all!


I've previously done a couple of apps which use video views - one for video capture (Android only), one for bar code scanning.

I found that the basic available samples worked quite well. However, once I started trying to extend them, then they became quickly fragile, they were hard to get working and they were quite frustrating to develop!

I would genuinely recommend starting your current develop as UI View code. After you've got it working, then you might find a nice way to split up the control and interface into a plugin - but I suspect that this won't be where most of your time is spent.


e.g. for my next QR code app, I plan to use the separate UI controls in https://github.com/Redth/ZxingSharp.Mobile - at the ViewModel level, I can hopefully just expose some sort of Command which acts on the decoded QR strings.

Stuart
  • 66,722
  • 7
  • 114
  • 165
  • My first opinion was to get the VideoView from my UI by using an Object property. So, I could cast to VideoView in my plugin library if monodroid for example or cast to any UI Element depending on wp7 or ios. I will study your answer. – Alphapage Oct 22 '12 at 17:31
  • Good luck! I think this is a bit like the Pull-To-Refresh sample - how pull-to-refresh worked was a feature of each UI layer - so there is no "portable plugin". If you did want to use an Object parameter, then I think I'd go for some sort of IVideoContainer wrapper - so the plugin could at least then query for IDroidVideoContainer or similar. – Stuart Oct 22 '12 at 17:38
  • Finally, I follow your instruction as usual! I create custom controls and bind to the ViewModel properties. Thanks again. – Alphapage Oct 23 '12 at 17:16
  • Excellent - I would *love* to see a sample - just screenshot or code level! – Stuart Oct 23 '12 at 17:56
  • Nothing terrific. I just include my axml video player in the View layout. My EditBox sets the ViewModel FileName property. I catch the Button Start event in my View and starts recording the ViewModel.FileName property as if it was a "classical" monodroid app, I mean no MvvmCross features really needed. I will try to give you my sample files soon even if it is very basic for you I think. – Alphapage Oct 24 '12 at 10:06
  • Yes - very basic - http://1.bp.blogspot.com/-8pqqn_7TMBY/TzMRnRnSlsI/AAAAAAAAAOM/8mjix_9o9k8/s1600/MidvaleSchoolForTheGifted.jpg – Stuart Oct 24 '12 at 11:12