Bug 21459 - Android.Media.MediaPlayer.AddTimedTextSource always fails with IllegalArgumentException
Summary: Android.Media.MediaPlayer.AddTimedTextSource always fails with IllegalArgumen...
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.14.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2014-07-19 11:28 UTC by Steve Williams
Modified: 2014-07-21 22:51 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Steve Williams 2014-07-19 11:28:56 UTC
I'm not sure where to find the Version number required above.  I'm using Xamarin and Xamarin Studio 5.1.4 (latest stable as of July 19 2014).

This code always fails with an IllegalArgumentException.

    var mediaPlayer = new Android.Media.MediaPlayer();
    mediaPlayer.AddTimedTextSource("source.txt", Android.Media.MediaPlayer.MediaMimetypeTextSubrip);

Android.Media.MediaPlayer.AddTimedTextSource() takes a mimetype as a string.  The only supported mimetype is "application/x-subrip" declared in a constant Android.Media.MediaPlayer.MediaMimetypeTextSubrip.  The Android source code [1] contains the following test for the mimetype

    private static boolean availableMimeTypeForExternalSource(String mimeType) {
        if (mimeType == MEDIA_MIMETYPE_TEXT_SUBRIP) {
            return true;
        return false;

This uses the Java String == operator which tests for the same string instance, not the same string contents.  Using Xamarin.Android, we will never be using the exact same Java String instance that is declared publicly in the Java code.  Therefore it always fails with an IllegalArgumentException.

Discovered by tributealx on the OUYA Dev Forums [2].

[1] https://code.google.com/p/android-source-browsing/source/browse/media/java/android/media/MediaPlayer.java?spec=svn.platform--frameworks--base.099fd80f984b8493de58bdda8ea05563261b0af2&repo=platform--frameworks--base&name=android-cts-4.1_r1&r=099fd80f984b8493de58bdda8ea05563261b0af2#1676
[2] http://forums.ouya.tv/discussion/3875/wrong-mime-type-for-subtitles-on-a-video
Comment 1 Atsushi Eno 2014-07-21 22:51:25 UTC
(Reporting to Xamarin but not to Android?)

Our API cannot really deal with such Google's internal implementation problem. If that's going to happen, everything will become slow to resolve to strings for almost pointless reason.
Whenever such an issue has happened, what should be done there is to fallback to JNIEnv or Java.Lang.Reflect.

(also http://developer.xamarin.com/guides/android/advanced_topics/java_integration_overview/working_with_jni/ )