iOS Tutorial iMedia library - Camera and VideoView

Discussion in 'iOS Tutorials' started by Erel, Oct 27, 2014.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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:
    Code:
    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:
    Code:
    #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:
    Code:
    #PlistExtra:<key>NSPhotoLibraryAddUsageDescription</key><string>Save photo in albums.</string>
     

    Attached Files:

    Last edited: Nov 19, 2017
  2. aaronk

    aaronk Well-Known Member Licensed User

    I noticed that you say it will allow you to stream videos (VideoView.LoadVideoUrl)

    Does this mean this library will let you stream a MJEPG stream (and H.264 streams) and display it on the screen within the app?

    What about if you have a IP camera that when you view the URL like: http://ip_address_here/snapshot.jpg it will display a snapshot of the camera.
    If you send that same URL it will give you another updated snapshot of the camera.

    Will this library let you then load that snapshot from the camera and automatically keep polling for the snapshot or would you say I need to download the snapshot another way and then load it into a imageview ?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Quoting Apple documentation:

    This class plays any movie or audio file supported in iOS. This includes both streamed content and fixed-length files. For movie files, this typically means files with the extensions .mov, .mp4, .mpv, and .3gp and using one of the following compression standards:

    • H.264 Baseline Profile Level 3.0 video, up to 640 x 480 at 30 fps. (The Baseline profile does not support B frames.)

    • MPEG-4 Part 2 video (Simple Profile)

    If you use this class to play audio files, it displays a white screen with a QuickTime logo while the audio plays. For audio files, this class supports AAC-LC audio at up to 48 kHz, and MP3 (MPEG-1 Audio Layer 3) up to 48 kHz, stereo audio.


    For an IP camera you can use HttpUtils2 to download the images.
     
  4. ilan

    ilan Expert Licensed User

    really great erel, b4i is awsome (and its only BETA), can i ask you one question, in this tutorial i see that you are using a simulator of iphone 5 on your PC (windows) what is it for a simulator?

    where can i download it please? thank you...
     
  5. inakigarm

    inakigarm Well-Known Member Licensed User


    I think is reflector; you can display the ios device on computer screen. You have to download the Pc soft and choose AirPlay on ios device

    http://www.airsquirrels.com/reflector/
     
    ilan likes this.
  6. Erel

    Erel Administrator Staff Member Licensed User

    That's correct. It is not an emulator.
     
  7. ilan

    ilan Expert Licensed User

    thanks i will check it out...
     
  8. borofan

    borofan Member Licensed User

    is there an object or library similar to this for recording audio?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Currently no (the video capture does include audio).
     
  10. tigrot

    tigrot Well-Known Member Licensed User

    Hi everybody, I'm porting our B4A APP to Iphone. The Android App starts a sequence of photo grabbing, as fast as the device can and trasfers to a remote host. A limit is imposed by Apple(this drives me crazy, since in 41 years I never had "limits" in what can be done and cannot), they don't allow to start a sequence of foto programmatically, without user's button press. I don't think it's viable in B4I. Am I right?

    Best regards
    Mauro
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    It is not possible to implement it in B4i. You can only let the user take a picture. You cannot send the preview images as done in the CCTV example.
     
  12. tigrot

    tigrot Well-Known Member Licensed User

    Well, I'm trying to extract the frame from a streaming video, convert to a Jpeg and send to the server. After developing with B4A, using Xcode(and objective-c) gives me the sensation to be in a Jail! Now I understand what "JailBroken" stands for... There are so many restrictions, which are reducing feasibility of my projects almost to zero chances. I have done the impossible with any kind of device, from micro to very large systems, but this time I'm very upset by the limits imposed by Apple...
    Thank you Erel, you are the best!
     
  13. Mark Turney

    Mark Turney Active Member Licensed User

    Having an issue, which is likely related to my newness with B4i, and complete lack of knowledge with iOS :confused:. For some reason, I cannot get a picture taken with my iPAD camera to fill an imageview I created with designer, called lastImage. Here is my code ... any suggestions would be appreciated. I've looked up and down the iMedia documentation and Camera example....
    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'Public variables can be accessed from all modules.
        Public App As Application
        
    Public NavControl As NavigationController
        
    Public cam1 As Camera
        
    Private Page1 As Page
        
    Private Page2 As Page
        
    Private Page3 As Page
        
    Private Page4 As Page
        
    Private lastImage As ImageView
        
    Private snapPic As Button
        
    Private tabcontroller As TabBarController
        
    Private resetBtn As Button
        
    Private sql1 As SQL
    End Sub

    Private Sub Application_Start (Nav As NavigationController)
        NavControl = Nav
        NavControl.ToolBarVisible = 
    True
        Page1.Initialize(
    "Page1")
        Page2.Initialize(
    "Page2")
        Page3.Initialize(
    "Page3")
        Page4.Initialize(
    "Page4")
        Page1.Title = 
    "Face Flashcards"
        Page1.RootPanel.Color = 
    Colors.Gray
        Page1.RootPanel.LoadLayout(
    "Home")
        NavControl.ShowPage(Page1)
        tabcontroller.Initialize(
    "tc")   
        cam1.Initialize(
    "cam1", Page1)
        sql1.Initialize(
    File.DirDocuments, "faceflashcards"True)
    End Sub

    'Took out page change code "here", as it is working fine...

    Private Sub Application_Background
       
    End Sub

    Sub snapPic_Click
        cam1.TakePicture
    End Sub

    Sub cam1_Complete (Success As Boolean, Image As Bitmap)
        
    If Success Then
            
    If Image.IsInitialized Then
                lastImage.Bitmap = 
    Image
            
    End If
        
    End If
    End Sub
    Thanks in advance for the assistance!

    Mark
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    What happens when you run your code?
    Put a breakpoint in cam1_Complete. Is Success true?
     
  15. Mark Turney

    Mark Turney Active Member Licensed User

    Good idea ... because, nothing happens after I snap the pic with the iPad camera. Once I click "Use Photo", the dialog closes and nothing populates the imageview.

    Will put in a break point ... thanks!

    Mark
     
  16. Mark Turney

    Mark Turney Active Member Licensed User

    Added some msgboxes, as follows...
    Code:
    Sub cam1_Complete (Success As Boolean, Image As Bitmap)
        
    If Success Then
            
    Msgbox("Success is true""cam1_complete")
            
    If Image.IsInitialized Then
                lastImage.Bitmap = 
    Image
            
    End If
        
    Else
            
    Msgbox("Success is false""cam1_complete")
        
    End If
    End Sub
    But, I get no response at all, as if the "complete" event is not being called at all.

    Thanks,
    Mark
     
  17. Erel

    Erel Administrator Staff Member Licensed User

  18. Mark Turney

    Mark Turney Active Member Licensed User

    I changed to Log("Success") or Log("Failure"). Please, excuse my denseness here, but I don't see anything recorded related to these logs. However, this is what is in the log...

    Application_Start
    Application_Active
    Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
    Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
    Application_Inactive
    Application_Background

    Thanks again Erel,
    Mark
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    See my previous answer.
     
  20. Mark Turney

    Mark Turney Active Member Licensed User

    Ahhh, thanks Erel. I'll take a look.

    Thanks,
    Mark
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice