Reputation: 3131
I am trying to retrieve the channel count of a .wav sound file using TrackInfo
and MediaFormat
but I cant seem to get a handle of a MediaFormat
object which i believe would provide the channel count.
I have tried following this instruction but it is not helping.
here is what I have so far
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(soundPath);
mediaPlayer.prepare();
TrackInfo info = mediaPlayer.getTrackInfo()[0];
MediaFormat mf =
Upvotes: 0
Views: 2175
Reputation: 121
You need to use MediaExtractor
and MediaFormat
to access the KEY_CHANNEL_COUNT
Here is an example,
MediaExtractor extractor = new MediaExtractor();
extractor.setDataSource(path);
//where path is a String variable and points to the data source
MediaFormat format = extractor.getTrackFormat(i);
//where i is an int variable and denotes the index value of a track.
//For the first track: i = 0;
int count = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
I would also recommend reading the example in MediaExtractor
Class Description from Android Developer Reference. Here is the link:
http://developer.android.com/reference/android/media/MediaExtractor.html
I hope this helps. Happy coding.
Upvotes: 4