As it is a hack using private API it might break, sure. But I don't
expect it to break before 2038 :). If it breaks it's not fatal for the
app (crash). Btw above code snippet should catch Throwable to catch
potential although unlikely UnsatisfiedLinkError.

I've tested above code on 2 devices, with and without WMA support.

With slight modifications, above hack can detect WMV support as well.

No need to say to resort to such hacks sucks...

On Aug 24, 4:32 pm, Mark Murphy <[email protected]> wrote:
> Are you sure that AUDIO_DECODER_WMA will always be the 0th indexed
> object in the constants array? I haven't looked at the code, and I
> haven't tried getting at an enum via reflection. That's the big thing
> that leaps out at me (besides the private APIs issue you mention).
>
>
>
>
>
>
>
>
>
> On Wed, Aug 24, 2011 at 7:13 AM, b0b <[email protected]> wrote:
> > In the meantime the abomination belows works. I know: "...private
> > api...might break....evil...don't do this...."
> > What's really missing is a public API to enumerate decoders and their
> > capabilities (in particular is decoding supported over HTTP).
>
> > public Boolean isWMASupported() {
>
> >                try {
> >                        Class decoderCapabilitiesClass =
> > Class.forName("android.media.DecoderCapabilities");
>
> >                        Class audioDecoderClass =
> > Class.forName("android.media.DecoderCapabilities$AudioDecoder");
> >                        Object constants[] = 
> > audioDecoderClass.getEnumConstants();
> >                        if(constants == null || constants.length == 0) 
> > return null;
>
> >                        Object AUDIO_DECODER_WMA = constants[0];
>
> >                        Method getAudioDecodersMethod =
> > decoderCapabilitiesClass.getMethod("getAudioDecoders");
>
> >                        List decoders = 
> > (List)getAudioDecodersMethod.invoke(null);
> >                        for(Object decoder : decoders) {
> >                                if(decoder.equals(AUDIO_DECODER_WMA)) return 
> > true;
> >                        }
> >                        return false;
>
> >                } catch (Exception e) {
> >                        return null;
> >                }
>
> >        }
>
> > On Aug 24, 12:51 pm, Mark Murphy <[email protected]> wrote:
> >> On Wed, Aug 24, 2011 at 4:39 AM, b0b <[email protected]> wrote:
> >> > If only google in its immense wisdom had provided
> >> > MediaPlayer.isMimeTypeSupported()...
>
> >> Yes, it's a stunning omission.
>
> >> --
> >> Mark Murphy (a Commons 
> >> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> >> Android App Developer Books:http://commonsware.com/books
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android Training in Oslo:http://bit.ly/fjBo24

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to