iOS Tutorial iMedia library - Camera and VideoView

VideoView is an object that makes it quite simple to play local or remote videos.

The most important thing to remember about VideoView is that the object itself is not a View (unlike in B4A). The view is exposed through its View property.

In order to play a video you need to:
1. Initialize VideoView.
2. Add VideoView.View to the layout.
3. Load the video with VideoView.LoadVideo or VideoView.LoadVideoUrl (for video streams).

The Ready event is raised when the video is ready for playback.
The Complete event is raised when the playback reaches the end.

Camera object allows you to take pictures, capture videos and also to select exiting pictures and videos from the device albums. Note that it only supports portrait orientation.

The main methods are:
Camera.TakePicture - Opens the Camera form and allows the user to take a picture.
Camera.TakeVideo - Opens the form and allows the user to capture video.
Camera.SelectFromSavedPhotos / SelectFromPhotoLibrary - Open the form and allows the user to select a picture or video from the device camera roll album or device photo library.

On iPads the existing media selection form is anchored to a view.

The complete event will be raised when the user closes the form:
B4X:
Sub Cam_Complete (Success As Boolean, Image As Bitmap, VideoPath As String)
   If Success Then
     If Image.IsInitialized Then
       vv.View.Visible = False
       ImageView1.Bitmap = Image
     Else
       vv.View.Visible = True
       vv.LoadVideo(VideoPath, "")
     End If
   End If
End Sub
If Success is true then either Image will be initialized and will hold the selected / taken photo or VideoPath will hold the path to the selected / captured video.


Starting from iOS 10 you need to add explanation about the camera usage:
B4X:
#PlistExtra:<key>NSPhotoLibraryUsageDescription</key><string>Select a photo.</string>
#PlistExtra:<key>NSCameraUsageDescription</key><string>Taking a photo.</string>
#PlistExtra:<key>NSMicrophoneUsageDescription</key><string>Record video.</string>

iOS 11+ also requires:
B4X:
#PlistExtra:<key>NSPhotoLibraryAddUsageDescription</key><string>Save photo in albums.</string>
 

Attachments

  • CameraExample.zip
    3 KB · Views: 612
Last edited:

azzam223

Active Member
Licensed User
Longtime User
Hello Erel when i try to take video the log display this message

B4X:
Warning: Attempt to present <UIImagePickerController: 0x17085400> on Page (vc): (null) whose view is not in the window hierarchy!
 

victormedranop

Well-Known Member
Licensed User
Longtime User
I recently bought the product, and I want to export some android applications and I would like to know with this library I can play m3u8
streaming, or any other library.

thanks,

Victor
 

Daniel Uribe

Member
Licensed User
Longtime User
Hello everyone!!

Please, in B4A we have:

B4X:
Sub imgChooser_Result(Success As Boolean, Dir As String, FileName As String)

When the user choose a image. There is a way to b4I?

I need get the Dir and the Filename when the user choose a image in

B4X:
Sub Cam_Complete (Success As Boolean, Image As Bitmap, VideoPath As String)

Thanks a lot!!
 

Francisco Picado

Member
Licensed User
Longtime User
I found the problem.
B4X:
#ATSEnabled: False

only allow https connections.

Victor

Hello Victor, I spent the last days reviewing this problem, because I wanted to play Streaming from a website, the code worked fine for me in iphone 5s, 6 + (
the the option # ATSEnabled:true and even so it worked reproduced http link), and think it will be the same in iphone 4s , but no. It was apparently trying to play the streaming, and because i'd read this post:

https://www.b4x.com/android/forum/threads/apple-restrictions-on-non-ssl-http-requests.69148/#content

I though that it doesn't matter even your put this option true or false , if you have ios 10 always have to be https., or in Cases you don't have a certificated domain, you can always exclude by this post:

https://www.b4x.com/android/forum/threads/ats-app-transport-security.74281/


With your help I already changed the value for the Iphone 4s, I Ask the forum: Should leave this option in False to be compatible with all models of Iphone or could activate or deactivate this option according to the Phone ???, I'm going to upload my app and i don't know if leaving in False is going to be a problem for the approve.

thanks.
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Hi Francisco, i got an free ssl certificate with lets sncrypt. and moved all the videos streaming to ssl.
i found on the web that Apple will no aprove applications without ssl on web connections. please let us know if you get your apps approved. that will be important.

i wish you get approved.

Victor
 

Francisco Picado

Member
Licensed User
Longtime User
Thanks Victor,

At the end my application was approved and works well with streaming from a site without Certificate and with the option #ATSEnabled: False. I had help from many post members to finalize the app, from Erel and also from your Reply about the error you were having Victor. Thank you so much
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Hi, I'm porting one of my apps to IOS, but having some problems with Imedia.
I transmitting with this format :

Audio -> MPEG Audio layer 1/2 (mpga)
Video -> H264-MPEG-4 AVC (part 10) (h264)

some help here, with Imedia. try this URL http://209.16.115.42:25081/

Thanks.

Victor

Note: I'm using an simulator. audio works fine, with online source mp3.
 
Last edited:
Top