Android Question get image from a video

Discussion in 'Android Questions' started by Lucas Eduardo, Mar 20, 2019.

  1. Lucas Eduardo

    Lucas Eduardo Member Licensed User

    Hello, i am trying to get image from a video. I did it when i recorded a video and went back to app, but when i use the ContentChooser i can't do this.
    How can i get the image from a video after i choose this image with ContentChooser?

    Here is my code to get the image after i record a video:
    Code:
    video.Initialize("video"'video is a process global VideoRecordApp variable.
            Dim folder As String = Starter.Provider.SharedFolder
            
    Dim FileName As String = "1.mp4"
            video.Record3(folder, FileName, -
    1, Starter.Provider.GetFileUri(File.Combine(folder, FileName)))
            
    Wait For Video_RecordComplete (Success As Boolean)
            
    If Success Then
                
    'Example of playing the recorded video
                Dim vidfile As String = File.Combine(folder, FileName)
                
    Dim rfl As Reflector
                
    Dim obj As Object
                
    Dim b As Bitmap
         
                obj = rfl.CreateObject(
    "android.media.MediaMetadataRetriever")
                rfl.Target = obj
                rfl.RunMethod2(
    "setDataSource", vidfile, "java.lang.String")
                b = rfl.RunMethod3(
    "getFrameAtTime"0"java.lang.long"3"java.lang.int")
       
                icVideoMediaAtividadeSuspeitaSvBullying.Bitmap = b
               
                
    ToastMessageShow("Vídeo recorded with success!"True)
            
    End If

    and code to choose an video

    Code:
    Dim cc As ContentChooser
            cc.Initialize(
    "cc")
            cc.show(
    "video/*""Choose video")
            
    Wait For cc_Result(Success As Boolean, Dir As String, FileName As String)
            
    If Success Then
                
    Log("vídeo choosed- Folder: " & Dir & "  file name: "&FileName)
                
    ToastMessageShow("Video choosed with success!"True)
       
            
    Else
                
    ToastMessageShow("Video not selected!"True)
            
    End If

    Thanks.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Is there any error message in the logs?

    What is the output of Log(vidfile)?
     
  3. Lucas Eduardo

    Lucas Eduardo Member Licensed User

    the output is /storage/emulated/0/Android/data/app.sao.luis/files/shared/1.mp4

    but i can get the image with this code
    Code:
    Dim vidfile As String = File.Combine(folder, FileName)
                
    Dim rfl As Reflector
                
    Dim obj As Object
                
    Dim b As Bitmap
         
                obj = rfl.CreateObject(
    "android.media.MediaMetadataRetriever")
                rfl.Target = obj
                rfl.RunMethod2(
    "setDataSource", vidfile, "java.lang.String")
                b = rfl.RunMethod3(
    "getFrameAtTime"0"java.lang.long"3"java.lang.int")
       
                icVideoMediaAtividadeSuspeitaSvBullying.Bitmap = b
    the problem is when i use the code to choose a video. How can i get the image?

    the output of log
    Code:
    Log("video choosed- Folder: " & Dir & "  file name: "&FileName)
    is
    Code:
    video choosed- Folder: ContentDir  file name: content://com.android.providers.media.documents/document/video%3A3979
     
  4. Lucas Eduardo

    Lucas Eduardo Member Licensed User

    i got it

    here is the code

    Code:
    Dim cc As ContentChooser
            cc.Initialize(
    "cc")
            cc.show(
    "video/*""Choose video")
            
    Wait For cc_Result(Success As Boolean, Dir As String, FileName As String)
            
    If Success Then
               
                
    ToastMessageShow("Video choosed with success!"True)
                
    Try
                    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_EXTERNAL_STORAGE)
                    
    Wait For Activity_PermissionResult (Permission As String, ResultCkeck As Boolean)
                    
    If ResultCkeck Then
                        
    Dim folder As String = Starter.Provider.SharedFolder
                        
    Dim newFileName As String = "1.mp4"
                       
                        
    Dim out As OutputStream
                        
    Dim input As InputStream
                        input = 
    File.OpenInput(Dir , FileName)
                        out = 
    File.OpenOutput(folder, newFileName , False )
                        
    File.Copy2(input, out)
                        out.Close
                       
                        
    'Log(File.Size(folder, newFileName))
                        Dim vidfile As String = File.Combine(folder, newFileName)
                       
                        
    Dim rfl As Reflector
                        
    Dim obj As Object
                        
    Dim b As Bitmap
         
                        obj = rfl.CreateObject(
    "android.media.MediaMetadataRetriever")
                        rfl.Target = obj
                        rfl.RunMethod2(
    "setDataSource", vidfile, "java.lang.String")
                        b = rfl.RunMethod3(
    "getFrameAtTime", -5"java.lang.long"2"java.lang.int")
                       
                        
    Dim i, j As Int
                       
                        i = b.Height * 
    0.3
                        j = b.Width * 
    0.5
                   
                        icVideoMediaAtividadeSuspeitaSvBullying.Bitmap = b.Resize(j,i,
    True)
                       
                       
                    
    End If
                   
                   
                
    Catch
                    
    Log(LastException)
                
    End Try
       
            
    Else
                
    ToastMessageShow("The video wasn't selected!"True)
            
    End If
     
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