SiliCompressor icon indicating copy to clipboard operation
SiliCompressor copied to clipboard

compressed video file not play in VideoView from WebServer

Open pritesh25 opened this issue 7 years ago • 39 comments

i'm developing application which record the video and save to web server, and since recorded video have too much size i use compression technique SiliCompressor in order to reduce size of original video.

after applying compression technique, video size reduces and i also play that compressed video file into my VideoView and till here working perfectly.

when i upload compressed video file to my live webserver and try to play video from url in VideoView, it's not playing.

However it work in my localhost server well.

can u help me what is problem ?

here is my code to play video from my live web server

VideoView vv = (VideoView)findViewById(R.id.vv);
      vv.setZOrderOnTop(true);

      try {
          MediaController mediacontroller = new MediaController(this);
          mediacontroller.setAnchorView(vv);

          Uri uri = Uri.parse(_video_link);
          vv.setMediaController(mediacontroller);
          vv.setVideoURI(uri);
          vv.seekTo(1);

      } catch (Exception e) {
          Log.e("Error", e.getMessage());
          e.printStackTrace();
      }

      vv.requestFocus();
      vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
          public void onPrepared(MediaPlayer mp) {

              mp.setLooping(true);
              vv.start();

          }
      });
      vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
          @Override
          public void onCompletion(MediaPlayer mp)
          {
              vv.resume();
          }
      });

pritesh25 avatar May 25 '18 05:05 pritesh25

what are you using firebase or what as your backend

zodiacvrish avatar May 31 '18 08:05 zodiacvrish

i am using php and MySQL as backend

pritesh25 avatar May 31 '18 08:05 pritesh25

did you solved or still facing error

zodiacvrish avatar May 31 '18 08:05 zodiacvrish

what do you want to compress video or image ...I can I help you

zodiacvrish avatar May 31 '18 08:05 zodiacvrish

still im facing error , I'm compressing video

pritesh25 avatar May 31 '18 08:05 pritesh25

are you compressing image

zodiacvrish avatar May 31 '18 08:05 zodiacvrish

no , not now because images size is not too much if i compared with video

pritesh25 avatar May 31 '18 08:05 pritesh25

use this to compress image it is very use full....

   private Bitmap decodeFile(File f) {
   Bitmap b = null;
    //Decode image size
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(f);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    int IMAGE_MAX_SIZE = 1024;
    int scale = 1;
    if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
        scale = (int) Math.pow(2, (int) Math.ceil(Math.log(IMAGE_MAX_SIZE /
                (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
    }
    //Decode with inSampleSize
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = scale;
    try {
        fis = new FileInputStream(f);
        b = BitmapFactory.decodeStream(fis, null, o2);
        fis.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Log.d(TAG, "Width :" + b.getWidth() + " Height :" + b.getHeight());
    try {
        FileOutputStream out = new FileOutputStream(thumb_filePath);
        b.compress(Bitmap.CompressFormat.JPEG, 50, out);
        out.flush();
        out.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return b;
}

zodiacvrish avatar May 31 '18 08:05 zodiacvrish

but of i want to compress video then what would you recommend me ?

pritesh25 avatar May 31 '18 08:05 pritesh25

for video

zodiacvrish avatar May 31 '18 08:05 zodiacvrish

yes for video

pritesh25 avatar May 31 '18 08:05 pritesh25

wait these types of libraries does not work as you expected I will give you the code....just be calm

zodiacvrish avatar May 31 '18 08:05 zodiacvrish

ok sure , I'll wait for your response.

pritesh25 avatar May 31 '18 08:05 pritesh25

ok good !!

zodiacvrish avatar May 31 '18 09:05 zodiacvrish

yo !!! the file is very big how can I send you.... I have the code...how can I send it to you ..it has 7 class

zodiacvrish avatar May 31 '18 09:05 zodiacvrish

upload the file on Google drive and share the link here or else you can mail me link personally too.

pritesh25 avatar May 31 '18 09:05 pritesh25

do u have facebook or Gmail or WhatsApp like thing

zodiacvrish avatar May 31 '18 09:05 zodiacvrish

yes here i my email [email protected] mail me on this email id

pritesh25 avatar May 31 '18 09:05 pritesh25

okkk done I will send you now

zodiacvrish avatar May 31 '18 09:05 zodiacvrish

are you facing this problem screen shot 2018-05-29 at 1 28 51 pm

zodiacvrish avatar May 31 '18 09:05 zodiacvrish

like your video cannot be played through download url

zodiacvrish avatar May 31 '18 09:05 zodiacvrish

yes video is not playing from the URL specially when the video is compressed and uploaded to the web server , file is completely uploaded to the web server I check the file size and everything , everything is working perfectly. but compressed video file is not playing through the URL

pritesh25 avatar May 31 '18 10:05 pritesh25

how did you get that compressed file from compress video()

zodiacvrish avatar May 31 '18 10:05 zodiacvrish

i use this compression technique (sillicompression)

pritesh25 avatar May 31 '18 11:05 pritesh25

https://github.com/RudreshJR/VideoCompression/blob/master/app/src/main/java/com/rudresh/videocompression/MainActivity.java

this link helps you see this if there is problem just come here we will talk about that

zodiacvrish avatar May 31 '18 11:05 zodiacvrish

or https://github.com/lalongooo/VideoCompressor this library by telegram

zodiacvrish avatar May 31 '18 11:05 zodiacvrish

SiliCompressor.with(Context).compressVideo(sourceVideoUri, destionationDirPath);

what should I pass here i am getting error ...he said that I should pass videouri, and file path but see

zodiacvrish avatar May 31 '18 11:05 zodiacvrish

mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mediaRecorder.setVideoEncodingBitRate(690000); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mediaRecorder.setVideoFrameRate(30); mediaRecorder.setVideoSize(640, 480); this code will hep to compress even crappy but you can set quality of video

zodiacvrish avatar May 31 '18 11:05 zodiacvrish

why am I getting this error UrisyntexException() wtf

zodiacvrish avatar May 31 '18 11:05 zodiacvrish

i already used this https://github.com/lalongooo/VideoCompressor library also but after using any compression technique to compress video file. that compressed video file not stream from the live web server (it work perfectly work in localhost).

pritesh25 avatar Jun 01 '18 04:06 pritesh25