2

Prolouge

I have a .wav file created using IBM Bluemix Watson Text to Speech, and I send it over the internet using a servlet that is provided with a specific key for the file.
I also have a media player that I create using

MediaPlayer player = new MediaPlayer();

The Problem

I use this in order to play a track that I download from a server.
At first I downloaded it to my internal storage but then realized that it is causing a problem since the player couldn't reach the file due to access limitations (the file wasn't readable by the media player since it needs to file to be world-readable).
Regardless the player didn't work no matter what I did, always writing:
08-20 22:57:51.092 20507-20973/com.bikebeacon E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
08-20 22:57:51.321 20507-20523/com.bikebeacon E/MediaPlayer: error (1, -2147483648)

Or

08-20 22:57:51.321 20507-20523/com.bikebeacon E/MediaPlayer: error (38,0)
08-20 22:57:51.321 20507-20523/com.bikebeacon E/MediaPlayer: error (-38,0)

Now my application first checks if there is external storage avaliable or not, if there is then it saves the file downloaded from the internet to a file in external storage (I checked, the file does exist, however I can't play it in my phone for some reason).
It is implemented like this:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
    AudioAttributes attr = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SPEECH).build();
    mediaPlayer.setAudioAttributes(attr);
} else 
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(new FileInputStream(trackFile).getFD());
mediaPlayer.prepare();
mediaPlayer.start();
response.close();

Note that mediaPlayer = new MediaPlayer();

If there is no external storage, the app tries to stream the app from the server, implemented like this:

 MediaPlayer mediaPlayer = new MediaPlayer();
                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                        AudioAttributes attr = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SPEECH).build();
                        mediaPlayer.setAudioAttributes(attr);
                    } else
                        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    mediaPlayer.setDataSource(NetworkDispatcher.URL_TYPES.FILE.toString());
                    mediaPlayer.prepare();
                    mediaPlayer.start();

After looking and digging through the entire log I saw a lot of attempts of FFMPEG trying to figure out what the **** is the file, and at the end it spits out:

D/FFmpegExtractor: ffmpeg detected media content as 'audio/x-wav' with confidence 0.08
......
E/GenericSource: Failed to init from data source!

I have no idea what to do or how to fix it, my theiories for what is happening range from corrupt WAV file, up to specific phone problem.

What I know so far:

  • The issue of "QCMediaPlayer mediaplayer NOT present" is an issue that occurs on either rooted devices, or specifically on OnePlus devices (leaning towards the former).

  • The issue of "error(1, -2147483648)" was given a solution in this thread (Android MediaPlayer throwing "Prepare failed.: status=0x1" on 2.1, works on 2.2), however, the answer they gave was either incorrect path (path is correct, triple checked), missing permissions (requesting both in manifest and runtime for internet and read\write external storage), or that it is an incompatible media type, which might be the reason.


My actual theory: I found a post that says that the format IBM provides (with the synthize method for their Text To Speech service) is unplayable in android (as seen here: https://developer.ibm.com/answers/questions/180732/seems-watson-text-to-speech-service-returns-a-wav.html). I have seen so many posts about this not working for people (the media player itself), and none of them (not even: Why MediaPlayer throws NOT present error when creating instance of it? which has a strangely vague answer) actually answered the problem at hand.

What can I do? I have absolutely no idea. The only idea I have is to edit the headers of the wav file (or the data of the wav file) in order to boost the confidence of the FFMPEG so that it can play it as a wav file.
On the other hand I might be completely wrong, in which case I would love if someone could correct me to the actual issue.

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Alon .G.
  • 182
  • 1
  • 10
  • Your question is not very clear. Can you play the downloaded file (i.e. the case when the device has external storage)? If you can't, can you play this file with the Music app, or any other app on your device? If you can play a file, but not the stream, is there an app that can play this file, given the URL? Can you stream this URL to your PC? Can you feed this URL to ffmpeg and play it before it is completely downloaded? – Alex Cohn Aug 21 '17 at 13:56
  • @AlexCohn - The downloaded file can be play on the computer, not on the phone, media players don't recognize it. Don't even know how to feed to URL to ffmpeg so I can't answer that, I can download the file from the URL to my pc and play it using BSPlayer. – Alon .G. Aug 21 '17 at 20:43
  • It looks like your problem is exactly described in the ibm dev question. The answer there is to modify the headers you receive, because it is incompatible with the Android player. If you don't know how to fix that, make your question shorter and more specific. – Alex Cohn Aug 22 '17 at 04:58

2 Answers2

0

Try using this library: https://github.com/brianwernick/ExoMedia this library wraps the exoplayer , easy to use for audio and video playback.

Moti
  • 462
  • 2
  • 6
  • 18
0

why you are using MediaPlayer for playing IBM text to speech?

why not just using their simple command?

something like that:

TextToSpeech.sharedInstance().initWithContext(this.getHost(TTS_URL));

you can find also more information at: https://github.com/watson-developer-cloud/speech-android-sdk

Sayuri Mizuguchi
  • 5,250
  • 3
  • 26
  • 53