android MediaExtractor MediaCodec seek - android

Question again, guys.
I use MediaExtractor and MediaCodec to play MP4 file on android device. Everything works fine until I try to add Extractor.seekto().
If I just play mp3 file with my player,seeking functions well. However, when I try it with MP4 file, the video is not updated. I tried to debug the code, finding out that the mPlayerExtractor.getSampleTrackIndex() always returns 1 (Refer to the audio track).
But I do not know how to fix it.
I cannot put all my code here. So please give me some advise first. Thanks a lot.
Update: I can seek backward for both mp4 file and webm file. If I seek forward with webm file, The video starts to play after the same time of jumped time of the seeking operation. For mp4 file, it just never starts again.

Related

How to replace audio of a video in Android

I'm trying to replace the audio of a video in Android.
I think to solutions like mute the video and put on it an audio track, but
that not works very well if you want to save the video with the track on.
Is there a way to replace the sound part of a video to make it savable?
Thanks in advance.
I guess there are easier solutions, but it seems to be possible to use ffmpeg on android (FFmpeg on Android might get you going at installing it). You can then strip the audio (if you have set an audiosource while recording), and add other audio to your video. You can find many example ffmpeg-commands on how to remove from and add audio to your video.

What format can I use to record on android and play it in ios

I have tried so many different formats when I record a audio on android, that I get dizzy by just thinking about it. When I record by using .wav on ios, I can play it on android without any problem. But Im not able to play the recorded audio from a android on a ios.
I have tried to play it as a base64 and streaming by using the url. I don't know what to do play it, since nothing seems to work. But if some one just can point me in the right direction when it comes to what format I should use to record the audio on android so I can play it on ios, I would be very greatfull.
What I have so far:
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setAudioSamplingRate(44100);
recorder.setAudioEncodingBitRate(96000);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
but I got no idea what I should name the file I record on (like this record.mp3). Im using cordova so I have to do it when I start the recording. I have tried mp4, m4v, m4a, mp4, mp4, mpeg4 and mpeg. I have tried to record the file as a wav file as well, but then I get audio/x-wav in my base64 string.. Do I need to change the samplingRate, bitrate, outputformat or audio encoder to something else if I want to use .wav (not x-wav) and still make it work on ios?
After googling this issue, it seems even the very popular app "Evernote" has the same issue, and users are gutted about it. I did come across this question here on SO:
audio format for iOS and Android
They use a web service to convert the files to mp3, which works universally. I am sure you could find some way to do this without a middle man, but it should "point you in the right direction".
Hope this helps.
Cheers

Streaming audio file and caching it

I want to stream an audio mp3 file and then play it through android media player plus I also want to cache this file, so that mediaplayer don't have to stream for recently played tracks.
I have tried using prepareAsync method but it doesn't give me access to buffer content, so I have decided to stream the audio file myself and then pass it to the media player for playing. I have achieved this by following this article here but this approach has a problem i.e. while transferring the file to media player it goes into error mode which causes my player to behave inconsistently.
When media player enters its error mode it doesn't come out of it automatically so I am forced to create a new media player and then re-provide it the downloaded file, this workaround causes the user to experience an undesired pause in the song playing.
So, does any one have improved an version of code given in above link? or do they know a better solution to this problem or is there is actually a library for streaming an audio file in android?
Thanks
The link you provided looks like a less than ideal solution (not to mention outdated). What you probably want is a local proxy server that gives you access to byte data before the MediaPlayer gets it. See my answer here for a little more explanation.

Additional .mp4 decoders for VideoView

I am building an app that downloads .mp4 files from the Internet and plays them.
It seems there are no decoders for this particular video type, and I only get audio, no picture. The same thing happens with the standalone player, so it is not a problem with the program or file.
Is it possible to use a user library for the decoding and plug it into VideView?
The .mp4 in question can be found here: https://www.coursera.org/modelthinking/lecture/preview_view?lecture_id=17
Thanks in advance.

Android VideoView streaming

I have a project with a VideoView in it I am streaming a video from online using this method:
mVideoView.setVideoURI(Uri.parse("http://db.tt/ij7w1Nw"));
My videos are mp4 files downloaded from Youtube. I then upload them to my dropbox, that is where the url comes from. This works fine if I download the video and do not make any changes to it, and upload it straight to dropbox. However if I try to make any changes to it for instance convert from .flv to .mp4, or change the size, then I upload it to dropbox it no longer plays in the VideoView. I get a dialog that says 'Unable to play video. Invalid streaming data'. If I take this same exact video and put it on the SD card either manually or even by having my app download it from the url then play it off of the SD card using
mVideoView.setVideoPath(path);
it works fine. I am using Wondershare Video Converter Platinum to do the conversions and size changes.
Is there some sort of specific encoding that is required to stream an mp4 file rather than play it from a local copy? Am I getting this because of some sort of bug/error with wondershare? Has anyone else experienced this type of problem, if so how did you end up fixing it.
Thank you.
The media format guide may help you see what's available. In my experience wrapping a H.264 AVC or MPEG 4-encoded video in a 3GPP container provides the easiest integration. Android is very fickle with both audio and video streaming.

Categories

Resources