Playing .MP4 video from raw resource folder - android

I've seen a number of similar questions, but so far I've not been able to get anything working.
I'm trying to playback a video (.MP4) from the res/raw folder and only get audio, no video. The video is short (about 3 seconds), small (350KB) and if I put the video on the device (Motorola Droid) directly, it plays fine. It also plays fine if I modify the app to read it from the SD card rather than the resource folder. The behavior is the same on both the emulator and the actual device.
Unfortunately, I need this video to be an intro shown just prior to the main screen for my app, so it has to be part of the package. Additionally, one of the app requirements is that the app is available offline, so I can't stream from a web server. I've tried a VideoView, SurfaceView and MediaPlayer, none of them work.
Is it possible to playback video from the resource folder? I've read something about compression possibly screwing the video up, is it possible to manually decompress the video and then play it, and if so, how would that work? This seems like it should be a pretty basic operation, am I just missing something?

I was having the same trouble, tried everything too, agree it should be easier... and documented. Just fixed by passing VideoView.setVideoUri a string with the android.resource protocol, as described here.
The first option doesn't work for me, but the second does:
Uri uri = Uri.parse("android.resource://[package]/"+R.raw.[video_resid]);
Hopefully works for you too.

Related

ExoPlayer playing currently recording media files

Let me refraise my question, I wrote it in a hurry.
Current situation:
I have set up a digital video recorder to record broadcasts provided via DVB-C. It is running on a raspberry 3B using TVHeadend and jetty/cling to provide UPnP and other possibilities to access media files. For watching recordings, I wrote an android player app using IJKPlayer, which runs on smartphones, FireTV and AndroidTV.
One hassle when playing media files which are currently beeing recorded is, that IJKPlayer doesn not support timeshifting. Means, when I start playing a currently recording file, I can only watch the length which is known by the player at that moment. Anything which is recorded afterwards can not be played. I need to exit the player activity and start it again. I have resolved that issue by "simulating" a completed recoding using a custom servlet implementation. Since the complete length of the recording is already known, I can use ffmpeg to accomplish this.
Future situation:
I plan to move away from IJKPlayer to ExoPlayer, because it supports hardware playback and is much faster when playing h.264 media. I can of course use the same solution like above, but as far as I have found out yet, ExoPlayer can support media files which are currently being recorded by using the Timeline class. However, I don't seem to find neither a usefull documentation nor any good example. Hence, I would appreciate any help with the timeline object.
Regards
Harry
Looks like my approach won't work. At least, I didn't find a solution. Problem is, that the server returns the stream size as it is during player-start-time. I didn't find a method to update the media duration for "regular" files.
However, I can solve the problem by changing the server side. Instead of accessing a regular file, I convert the file to m3u8 in realtime, using ffmpeg. I then throw the m3u8 URI onto the player and it updates the duration of the stream (while playing) without the need to create any additional code on the client side.

Video sharing across Android, IOS

Objective: i) I want to play video that i captured on my android phone to IOS and vice versa.
Problem: Android captures it in mp4 while IOS plays in Mov.
Solution: I can do conversion of formats before uploading to server but thats a slow process
and causing performance issues.
Is there any library or solution that does it without slow it down?
I believe whatsapp does it by only uploading stream and making it correct format when someone requests to play it. Im not sure though how they do it.
Why not play the mp4 video on iOS? What need is there to convert?
EDIT: Also forgot to mention, mp4 and mov are basically the same format. You can literally just rename the extension (on iOS at least) and the video still plays.

StageVideo/NetStream on Android Downloads Entire Video Before Playing

I am (at long last) at the very end of a VOD project. It works perfectly, except on Android. Basically, on Android video will not play until the entire video has downloaded. A media server was well out of scope, so we are just serving the videos up from AWS S3. Works fantastically on iOS. Both streaming and downloading the video works exactly as you would expect it to. On Android, it just doesn't seem to want to play before the download finishes. It works well when using a server on the local network (I even see the occasional buffer, so I know it's not just quickly downloading), but nothing remote.
My only guess is that it is to do with the differences in the way iOS and Android stream video. On iOS, video streams via byte-range requests. Every few seconds, it will time itself out and request another range of bytes for the file. On Android, it only sends a single request for the entire file. Not sure how that could be fixed, however.
Does anyone have any tips or pointers here? Any help would be greatly appreciated here.
Happens on Android 4.4 and 4.3.
Using both a remote prod server we own and AWS S3.
AIR 3.9 with Flex 4.11
Utilizing StageVideo and NetStream
Test devices are a Nexus 5 and a Nexus 4
The issue was with the videos themselves. AIR for Android uses the standard approach to streaming where the entire file is requested and it reads it bit-by-bit (as opposed to iOS which requests specific byte-ranges repeatedly).
The problem here is that the player cannot begin playback until the video's metadata has been read. A standard h.264 encode sees the metadata (moov atom) located at the very end of the file, so the video does not begin until the entire video has been downloaded.
Easiest way I have found to fix this is re-encoding the videos through Handbrake with the "Web Optimized" option selected. This will ensure the metadata is located at the very beginning (byte 24, I believe) so the video should begin playing instantly.
Explanation from Adobe
Thread that gave me the idea to use the "Web Optimized" option

see several videos from rtsp on android device?

I just want to know if I can see several videos at once from the network using rtsp? I'm trying to do an android app similar to video surveillance and I need to see several videos at the some time in the screen, I tried to use it with MediaPlayer and after that with VideoView, but in the both cases sometimes the videos appear, sometimes give me an error that can not play one or more videos...What can I do to put it to work well?
What Cruceo said is correct. It's better to mux (FFmpeg is really great) all streams in one stream with a incredible resolution with a low bitrate & framerate. Then create a program to display it and make zoom in when you select a viewpoint.
A other option would be to change the video streams into jpg files. This way is allot easier because you can use your web browser to display it. With your web browser you can make use of JavaScript (ProcessingJS is very easy and good at this) to make a image viewer with allot of functionality.

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