I am using UIImagePickerController to pick videos in a messaging app. These videos can then be played back on either an iOS app, Android app or Web app. I am using the code below.
let picker = UIImagePickerController()
picker.delegate = self
picker.mediaTypes = ["public.image", "public.movie"]
picker.videoQuality = UIImagePickerControllerQualityType.typeMedium
if #available(iOS 11.0, *) {
picker.videoExportPreset = AVVideoProfileLevelH264Baseline30
}
This works fine and the video message sends and plays back fine on iOS and web but when playing back in an Android VideoView I get a "Can't play this video" message. The video is definitely being saved to the Android device in the correct location as I can pull it from there using Android Device Monitor and see that it is definitely h264 but there is something about the file the Android VideoView doesn't like.
What am I missing to make these videos picked on iOS play on an Android device? I'd really rather not transcode them on a server because that will massively slow down the message delivery time.
Thanks for your help
To answer my own question in case anyone else needs it.. The iOS file was actually a .MOV even though it was encoded with h264 and saved as .mp4.
I used the function from this post to convert the .MOV to mp4 and problem solved.
Swift - How to record video in MP4 format with UIImagePickerController?
Related
I am recodring video via UIImagePickerController. Then I upload my video to PHP server. But Android is not able to play video after downloading it from server.
UIImagePickerController returns video in .MOV format. I save this video in .mp4 format (just by changing file extension according to Second answer in this question) . To play it in android.
In iOS i am able to play video after downloading it from server but not in android. I think this is codec issue. Android does not support all iOS video codec. Someone please help :)
What should I do so that Video is compatible on iOS and android both.
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.
Im building an application where Im using cordova media to record audio on both ios and android. I encode the audio to a base64 string and send it to a server (parse.com) and save it as a file. When I want to play it, I play the url from the file after I click on a button on the devices. When I record the audio as a wav file on ios I can play it on both ios and android. But when I record on android I can only play it back on android devices.
Im struggling to find a format which I can record on android and play it on ios. I have tried wav, mp3, mp4, aac and 3gp. I have tried amr as well, but then it looks like it download the file to the phone and that is not what I want to do.
Can someone please help, Im really lost here.
Here's what I used. It plays audio properly in iOS.
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setAudioSamplingRate(44100);
recorder.setAudioEncodingBitRate(96000);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
I'm facing a strange problem. I tried to play a mp4 video on android devices and it fails to play when video is hosted on my server but same video file plays in same android devices if hosted on other server. I'm facing this problem only in android devices I can play video on my desktop no matter wherever it is hosted. Has anyone else ever faced such problem ?
Obviously its a server problem. But I Cant figure out how to change the settings that enable mp4 to play in android devices!
Server : apache2.2.3
Thanks.
Update your httpd.conf to add the MIME type for mp4
AddType video/mp4 .mp4
If you have a password restriction (like .htaccess), try and remove it and test again. Even if Chrome knows your password, the video player may not, and it doesnt prompt you for it. When played full screen, the player just says 'sorry, this video can not be played'.
I am new to android and trying to streaming video from my server.
When i run the application it gives Error "sorry,this video is not valid for streaming to this Device.." than i download and push to sdcard of my device(samsung Galaxy 5)this time video is playing.... i convert this video by SOTHINK VIDEO CONVERTER..
Any Help??
Thanks..
We ran into exactly the same problem, and I found a solution at this link:
http://code.google.com/p/android/issues/detail?id=9044
In short, if you have access to a Mac, you can encode the videos using HandBrake. Be sure to check the "Web optimized" checkbox. I'm encoding as format:MP4 file, Video Codec: H.264. After I did this and uploaded I was able to view the videos (or at least listen to them) in a 2.1 simulator, which had been giving that exact warning message before. I have not been able to get a hold of an actual 2.1 device, but I suspect it will work. When I confirm that I'll check back in here to let you know.
It seems that you are talking about sothink video encoder engine. Actually this program only supports the apple devices in ios system, for example, iphone, ipad and ipod.
Here is the official product homepage of sothink video encoder engine, and hope it helps!
http://www.sothinkmedia.com/flash-video-encoder-command-line/
The only issue for error "sorry,this video is not valid for streaming to this Device.." is that there is some problem in video format. Just correct the format/codec of mp4 and then it would run gracfully.