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.