Cordova/Crosswalk <video> element only plays once, then black - android

I have an issue with the latest cca, if I add a <video> to the page and play it it pretty much always works the first time. If I then try to play the video again the view appears to come to the surface but the video never actually plays.
I've found various bug reports and PRs but the issue still prevails.
https://github.com/crosswalk-project/crosswalk/pull/1827/commits/67ad7129c37ff98b049469e673bfa46f3dfdb856
https://crosswalk-project.org/jira/browse/XWALK-7215
I've tried cache busting the video, destroying and recreating the element, stopping and rewinding and then playing the video but nothing seems to work.
The video(s) are all mp4 with an aac audio track, f-frames are disabled and I've tried webm videos as well.

Answering my own question, there was a couple of issues with the particular setup and the video files.
The Cordova app is running on Android, on an ODroid C2.
For some reason the MP4 container doesn't work on this particular setup, WebM works 100% of the time.
Some of the videos were VP9 encoded which didn't work in either MP4 or WebM container.
The fix is to use VP8 encoding in the WebM container.

Related

How to record (and process?) a video that is streamable from Android

My company's app relies heavily on video recording and playback of web-based videos. I use the MediaRecorder API to record videos, through this library designed by me: https://github.com/afollestad/material-camera.
For playback, I use this library which is basically a wrapper around Google's ExoPlayer library: https://github.com/brianwernick/ExoMedia.
It works fine for the most part with small videos, especially if I decrease bit rates for audio and video. However, larger and higher quality videos have many issues. Sometimes they seem to buffer forever, sometimes playback doesn't even start successfully, etc. Again, these videos are being streamed over HTTP from Amazon S3.
I've read a little bit about FFMPEG, and how it can process MP4's for "faststart", splitting the files into chunks for DASH, etc. However, FFMPEG solutions for Android seem a bit complex, so...
Is there anyway to record MP4's from Android, with MediaRecorder, MediaCodec, or some other API which results in a video file that is fast to stream? It amazes me how well Snapchat has figured this out.
Well, I ended up trying the stock MediaPlayer API again. As long as you're on API 16 or above, there should be no major issues with the default hardcoded buffer size.
I ended up making a small library in case others need a nice solution to video playback: https://github.com/afollestad/easy-video-player

Why would HLS stream distort in Stagefright 1.2 when ts files change?

I've set up Apache 2.0 with several .m3u8 files serving a set of mpeg2ts files over HLS. These ts files were produced with libavformat by transmuxing an MP4 I downloaded from youtube. When I play the resulting HLS on VLC or QT, everything works fine. But on Android (Stagefright 1.2) the video has several problems:
The option to go full-screen does not work
The video duration says 1:40 when it is actually 2:00
The video sometimes fails to start and you have to reload page
The video reliably distorts (tears and pixelates) at transition points when switching the underlying .ts streams.
Some of this is ameliorated if I don't use HTML5's tag. But problem #4 remains.
I can play other m3u8's on Stagefright without any of the above problems, so I am assuming my transmuxing code is wrong, but even forgoing it and using the (recently added) HLS segmenting features of ffmpeg I have the same problem. Recoding with libx264 changes nothing.
I am at wit's end debugging this.
Android's libstagefright (along with mediaservice's NuPlayer) is not so mature product as vlc and a lot of troubles which are not present while using vlc are present in android it is much more vulnerable for any broken, corrupted, deviated content.
Such pixelation/macroblock artifacts are usually present while some frames where dropped (by android code or were lost) before decoding.
If those corruptions are present along with some green fields it might be a problem with synchronization of format change with a key frames (which might be a result of wrong implementation of source, or in part which notifies ANativeWindow about format change).
In corner case you might not get any green frames but crop/reolution would be deviated and pixelation might be visible).
What I would do:
1) Check for frame dropps
2) Check with some analyzer frames at the borders of consecutive sections

Stuttering playback on large MP4 with Vitamio

I'm creating an app that has a function that plays user selected video's. Nothing fancy, just playback of video's on the device itself without any advanced settings. Since MediaPlayer has issues with some video types I use Vitamio. It works great on smaller compressed video's but when I select a mp4 video that I've recorded with my phone itself it stutters, both audio and video. I tried changing video quality of the Vitamio Media Player, but it doesn't seem to have any effect.
I'm quite stuck in finding a solution, anyone who has any experience with this?
Please sure the video you recorded is ok, you can playback the video use VPlayer. or pull the video to your computer playback it.
if first ok ,you can try use Vitamio hardware decoder playback it.

Android audio lag while playing MPEG-TS file

I've recently been struggling a lot with playback of a video inside an Android app. The video in question is an M3U8 file, which in turn links to a series of secondary M3U8s, each of which has a list of component MPEG-TS video files, and a single M3U8 file containing the audio components in AAC format. I had a fair bit of trouble making M3U8 cooperate, however that now seems to be working OK.
Unfortunately, the audio is lagging about a second behind the video. This lag is present both in my own Activity containing a MediaPlayer, and simply launching Android's default video player pointing to the stream. There is also frequent visual stuttering or corruption in the playback. Neither issue is present when played with VLC Beta, or in the iPhone version of this app, hence it's not a problem with the video file itself. I tried the Vitamio library, this ran even worse (far more frequent corruption, and no audio at all). Regrettably, changing the video format is not an option.
It seems to me that this issue may be caused by Android's limited support for MPEG-TS - the list of supported media formats specifies that it uses the AAC audio (whereas I assume the iOS version is simply playing both video and audio from the .ts file). Any recommendations/solutions for fixing this lag?
You could try Gstreamer which seems to work well on Android (http://gstreamer.com/), also Vitamio is

Sorry, this video cannot be played - streaming mp4 to android

I've searched all over for a solution to this (including SO), however still haven't found a solution.
I need to have a simple video playback in my app. It's a bit less straightforward than a simple window with a video. Simplified, I have two layouts on my screen, one containing some other stuff and the other is to have the video window. There's also a button to switch between the two. This all works just fine, after I figured out that the videoview cannot be present on a view with visibility 'gone' - therefore I'm adding/removing it to/from container layout when needed.
However, I have the problem with the actual video playback. When I try to activate it, I get the dreaded error Sorry, this video cannot be played. One of the questions here on SO is discussing video formats (Android -- Can't play any videos (mp4/mov/3gp/etc.)?) - however I already have what seems to be the correct format, with 320px width and everything else. One of the answers on that thread mentions that videos from here "definitely work". I tried a couple from there - but I got another common beast: Sorry, this video is not valid for streaming to this device.
Please note that I'm testing on an actual device, as video playback is not working in the emulator. Also note that the solution must work on Android 1.6 and above (client's requirement). The device I'm testing on is LG GT540 Optimus with Android 2.1 (at present I don't have any other devices available).
From what I figured out, if I don't use qt-faststart on the videos, I get error Sorry, this video is not valid for streaming to this device. If I do use qt-faststart, then I get Sorry, this video cannot be played.
Here's my code for the playback:
VideoViewer videoPlayer = new VideoViewer(this);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoPlayer);
videoPlayer.setMediaController(mediaController);
videoPlayer.setVideoURI(Uri.parse(object.getVideoURL()));
LinearLayout container = (LinearLayout)ObjectInfo.this.findViewById(R.id.VideoContainer);
container.setVisibility(VISIBLE);
container.addView(videoPlayer, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
videoPlayer.requestFocus();
videoPlayer.start();
Now, the video I'm trying to play is to be progressive-downloaded from HTTP: object.getVideoURL() returns http://www.ooklnet.com/files/381/381489/video.mp4
Can anybody please help me sort this out? This is the last thing I need to complete before the whole app is ready.
Many thanks!
Edit: I tried using MediaPlayer - but got even worse results than with VideoView, so went back to VideoView. Now, in simulator, I get a black screen with controls hovering over it and the sound of the video is playing fine, also the progress is adjusting as the playback continues. However on my actual device, I'm still getting Sorry, this video cannot be played. error
Turned out the problem was with the format of the videos (specifically, the parameters I used with ffmpeg to create the MP4 videos). I ensured that the videos are baseline H.264 - and everything worked properly. See this question for more details.
Maybe you need to change the way you set up your MediaPlayer. I just plugged the url of your sample video into the apidemos example and it worked just fine.
See:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Video.html
Hope that helps.

Categories

Resources