Search code examples
androidurlunicodehindi

Android: MediaPlayer can't load URL with Hindi characters


An exception is thrown when I run this code. If you replace the Hindi characters in the URL with "Hello" it plays the file just fine.

When I load this URL (with the Hindi characters) in a browser it plays just fine.

What's going on?

Here's my code:

MediaPlayer mediaPlayer = new MediaPlayer();

mediaPlayer.setDataSource(getResources().getString(R.string.test)); 

mediaPlayer.prepare(); 

Here's the string resource def:

<string name="test">http://translate.google.com/translate_tts?q=आलू</string>

Solution

  • I don't think unicode characters are legal in URLs, unless you encode them. Here's the spec: https://www.rfc-editor.org/rfc/rfc1738