Reputation: 121
I'm new here and fresh to Android development. Here is my first question here.
I'm using MediaExtractor
and MediaCodec
to play mp4
file, with video and audio. Now I get one pair of extractor/codec for video and another pair of extractor/codec for audio, realized in two separate threads.
My question is: can I use just one extractor with two codecs to play video and audio synchronously?
If yes, How to do it? When I used extractor.selecttrack for one, the other won't work...
Thanks a lot.
Thanks to everyone's answer here. I have figure this out. I made a mistake that the extractor can only select one track. Actually, you can select more than one track, and extractor.advance() will read each track at one time subsequently.
Upvotes: 2
Views: 3052
Reputation: 121
Thanks to everyone's answer here. I have figure this out. I made a mistake that the extractor can only select one track. Actually, you can select more than one track, and extractor.advance() will read each track at one time subsequently.
Upvotes: 4
Reputation: 13317
Yes, you should use just one extractor, and one MediaCodec instance per track.
You shoudldn't use MediaExtractor.selectTrack in this case, you should just read the packets from all tracks, and for each packet returned choose which MediaCodec to pass it to.
Upvotes: 3