Android Question Recording Video with Audio Library

Giuliano Cucchiarini

Member
Licensed User
Longtime User
Hi
I am trying to record some video using the Audio library and the VideoRecordApp object.
My question is: Is it possible to control the Quality of the video Recording?

My problem is that I need to have files as small as possible.

Thank You

Giuliano C.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Giuliano Cucchiarini

Member
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
@ShortName("VideoRecordApp")
   @Events(values={"RecordComplete (Success As Boolean)"})
   public class VideoRecordApp {
     private IOnActivityResult ion;
     private String eventName;
     /**
      * Initializes the object and sets the sub that will handle the event.
      */
     public void Initialize(String EventName) {
       this.eventName = EventName.toLowerCase(BA.cul);
     }
     /**
      * Calls the recording application.
      *Dir and FileName set the output file location.
      */
     public void Record(final BA ba, final String Dir, final String FileName) {
       Record2(ba, Dir, FileName, -1);
     }

     /**
      * Calls the recording application.
      *Dir and FileName set the output file location.
      MaxLengthSeconds - Sets the maximum duration (in seconds).
      */
     public void Record2(final BA ba, final String Dir, final String FileName, final int MaxLengthSeconds) {

       if (eventName == null)
         throw new RuntimeException("You should first call Initialize.");
       ion = new IOnActivityResult() {

         @Override
         public void ResultArrived(int resultCode, final Intent intent) {
           ion = null;
           boolean success = resultCode == Activity.RESULT_OK;
           if (success) {
             ba.submitRunnable(new Runnable() {

               @Override
               public void run() {
                 try {
                   String uri = intent.getData().toString();
                   if (uri.startsWith("file://")) {
                     if (uri.equals(Uri.parse("file://" + File.Combine(Dir, FileName)).toString()) == false) {
                       File.Copy("", uri.substring(7), Dir, FileName);
                     }
                   } else {
                     File.Copy(File.ContentDir, intent.getData().toString(), Dir, FileName);
                     BA.applicationContext.getContentResolver().delete(Uri.parse(intent.getData().toString()), null, null);
                   }
                   ba.raiseEventFromDifferentThread(VideoRecordApp.this, null, 0, eventName + "_recordcomplete", false, new Object[] {true});
                 } catch (Exception e) {
                   e.printStackTrace();
                   ba.setLastException(e);
                   ba.raiseEventFromDifferentThread(VideoRecordApp.this, null, 0, eventName + "_recordcomplete", false, new Object[] {false});
                 }
               }

             }, null, 0);
           }
           else {
             ba.raiseEvent(VideoRecordApp.this, eventName + "_recordcomplete", false);
           }
         }

       };
       Intent i = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
       i.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
       if (Build.VERSION.SDK_INT >= 18) {
         String dir = Dir;
         if (Dir != File.getDirRootExternal() && Dir != File.getDirDefaultExternal())
           dir = File.getDirDefaultExternal();
         i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.parse("file://" + File.Combine(dir, FileName)));
       }
       if (MaxLengthSeconds > 0)
         i.putExtra("android.intent.extra.durationLimit", MaxLengthSeconds);
       ba.startActivityForResult(ion, i);
     }
   }
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Did you ever get the video quality improved? If so, can you provide an example your method?
Thanks,
Rusty
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Erel or others, can you advise me on how we can improve the video quality for this function?
Thanks,
Rusty
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks Erel,
I'm not familiar with how to build a library from Java code, can you advise/provide a url?
Rusty
 
Upvote 0
Top