jaeger25 / Html5Video

A Phonegap plugin that allows playback of local video files using html 5 video tags
Apache License 2.0
99 stars 65 forks source link

Use downloaded video files? #23

Open Duncank opened 10 years ago

Duncank commented 10 years ago

Is it possible to use video files that have been downloaded to the device later? They end up in a data-folder or a folder on the sdcard, but not inside the app package itself.

gylippus commented 10 years ago

Hey @Duncank,

I just did this for my app with files downloaded from FileTransfer with one change.

  1. In HTML5Video.java Change like 29 to point to your download location. For me I was using cordova.file.dataDirectory:

convertedVideos.put(tagNames.getString(i), "file:///data/data/packagename.something.com/files/" + video[0] + ".mp4");

The plugin normally also tries to use a videoid int, but I am using video[0] for the file name instead. Granted I have only been needing to initialize one video at a time so I will let you know what happens when I try multiple.

Let me know if this helps at all.

Using a downloaded file location also makes it work on Android 4.4+ !!!!!!! Note: @jaeger25

winstef commented 9 years ago

Hey @gylippus is your change works only for Android 4.4+ ?

I'm trying to get it to work on 4.2.2 but since the Webview does not allow file:/// I'm wondering how to play a video from the download location (cordova.file.dataDirectory) ?

gylippus commented 9 years ago

@winstef I used this solution for all version. I actually found though that certain devices (like HTC Desire and some Samsung) would not even allow using mediaPlayer from downloads in cordova.file.dataDirectory although almost every other device would.

I ended up using cordova.file.externalDataDirectory in the end.

The last hurdle that I'm still not 100% past is finding the absolute perfect codec combination to use in Handbrake of ffmpeg to cover 100% of devices with that as well.

Just as a caveat, one other change I had to make for the HTC Desire was to set the file permissions manually after downloading via the download method of FileTransfer.java

                    Log.d(LOG_TAG, "Download file:" + sourceUri);
                    //HTC Desire and some other devices need the following permission
                    file.setReadable(true, false);

                    FileProgressResult progress = new FileProgressResult();
jaeger25 commented 9 years ago

Feel free to submit a pull request and I can merge any changes in

Sent from my Windows Phone


From: gylippusmailto:notifications@github.com Sent: ‎10/‎28/‎2014 12:32 PM To: jaeger25/Html5Videomailto:Html5Video@noreply.github.com Cc: Matt Jaegermailto:matthew.jaeger@gmail.com Subject: Re: [Html5Video] Use downloaded video files? (#23)

@winstef I used this solution for all version. I actually found though that certain devices (like HTC Desire and some Samsung) would not even allow using mediaPlayer from downloads in cordova.file.dataDirectory although almost every other device would.

I ended up using cordova.file.externalDataDirectory in the end.

The last hurdle that I'm still not 100% past is finding the absolute perfect codec combination to use in Handbrake of ffmpeg to cover 100% of devices with that as well.

Just as a caveat, one other change I had to make for the HTC Desire was to set the file permissions manually after downloading via the download method of FileTransfer.java

                    Log.d(LOG_TAG, "Download file:" + sourceUri);
                    //HTC Desire and some other devices need the following permission
                    file.setReadable(true, false);

                    FileProgressResult progress = new FileProgressResult();

Reply to this email directly or view it on GitHub: https://github.com/jaeger25/Html5Video/issues/23#issuecomment-60816965

gylippus commented 9 years ago

@odbol & @Duncank Have either of you run into any issues with videos playing on some Samsung devices with custom ROMs?

For some of our users the videos just show up as white boxes and nothing else. I gave in and bought a Samsung S3 and installed Dirty Unicorns 4.4.4 [Final KitKat Version].

When I review the Logcat logs I am getting the following error (the same error repeats about 20 times before failing on the last line) which point to an OpenGL issue which I haven't been able to find a workaround for yet:

01-05 11:32:14.604: E/MediaPlayer(4560): Should have subtitle controller already set
01-05 11:32:14.669: E/chromium(4560): [ERROR:gles2_cmd_decoder.cc(5942)] [.Compositor-Onscreen-0x5e458860]GL ERROR :GL_INVALID_OPERATION : glUseProgram: program not linked
01-05 11:32:14.669: E/chromium(4560): [ERROR:gles2_cmd_decoder.cc(5718)] [.Compositor-Onscreen-0x5e458860]GL ERROR :GL_INVALID_OPERATION : glUniformMatrix4fv: wrong uniform function for type
01-05 11:32:14.669: E/chromium(4560): [ERROR:gles2_cmd_decoder.cc(5718)] [.Compositor-Onscreen-0x5e458860]GL ERROR :GL_INVALID_OPERATION : glUniform1iv: wrong uniform function for type
01-05 11:32:14.714: E/chromium(4560): [ERROR:gles2_cmd_decoder.cc(5942)] [.Compositor-Onscreen-0x5e458860]GL ERROR :GL_INVALID_OPERATION : glUseProgram: program not linked
01-05 11:32:14.714: E/chromium(4560): [ERROR:gles2_cmd_decoder.cc(5718)] [.Compositor-Onscreen-0x5e458860]GL ERROR :GL_INVALID_OPERATION : glUniformMatrix4fv: wrong uniform function for type
01-05 11:32:15.999: E/MediaPlayer(4560): Should have subtitle controller already set
01-05 11:32:15.999: D/AudioPlayer(4560): Send a onStatus update for the new seek
01-05 11:32:16.084: E/chromium(4560): [ERROR:gles2_cmd_decoder.cc(5942)] [.Compositor-Onscreen-0x5e458860]GL ERROR :GL_INVALID_OPERATION : glUseProgram: program not linked
01-05 11:32:16.084: E/chromium(4560): [ERROR:gles2_cmd_decoder.cc(5718)] [.Compositor-Onscreen-0x5e458860]GL ERROR :GL_INVALID_OPERATION : glUniformMatrix4fv: wrong uniform function for type

01-05 11:32:16.334: E/chromium(4560): [ERROR:logger.cc(46)] Too many GL errors, not reporting any more for this context. use --disable-gl-error-limit to see all errors.
odbol commented 9 years ago

Sorry I've never seen that before, and I've tested this on a SGS3 with stock 4.3 ROM. Seems like it's probably a custom ROM issue...

lalop commented 9 years ago

Hy @gylippus ,

I've found the same errors, did you finally found a solution ?

gylippus commented 9 years ago

@lalop unfortunately not. Would love to find out a way to though. The only progress I was able to make on this was to at least test and confirm that it does indeed work fine if the app is using Crosswalk. We are going to work on trying to improve the error handling for the plugin and hopefully that might be able to shed some light. Will share anything we do find.

lalop commented 9 years ago

@gylippus I've reencoded my video via handBrake, I can play it now

gylippus commented 9 years ago

@lalop, very interesting, any chance you can share the Handbrake settings that you used? Maybe even the video. Would be interested to it on the device we had the custom ROM on.

lalop commented 9 years ago

I use the android preset, with 30fps, 1000kbps as average bitrate and profile baseline. I can't share the video sorry

sauvainr commented 8 years ago

@gylippus I attempt to play downloaded files by following your way:

Unfortunately the file still dont playback. Have you made other changes? Thanks in advance

sauvainr commented 8 years ago

I finally make it work by.. not using html5video at all.

So for app which plays videos in a html tag and requires offline playback:

Hope this save hours of research for someone else. :)

ozooner commented 8 years ago

@sauvainr, are you using entry.toNativeURL() with and just setting it as video src?

sauvainr commented 8 years ago

Hi just the fileEntry.toURL() method.