Reputation: 41
I'm trying to get audios from firebase storage and play with MediaPlayer. And actually I can do this but the problem is I can't play some of the audios. I realized that it can't play audios which have size higher than 50 kb. I can play audios which the size less than 50 kb.
Btw this is my first question here. Sorry for mistakes.
Errors:
E/FLACExtractor: unsupported sample rate 44000
E/GenericSource: initFromDataSource, source has no track!
E/GenericSource: Failed to init from data source!
E/MediaPlayerNative: error (1, -2147483648)
E/MediaPlayer: Error (1,-2147483648)
public class KelimeSecimActivity extends AppCompatActivity implements MediaPlayer.OnPreparedListener {
MediaPlayer mMediaplayer = new MediaPlayer();
private Button buttonBasla ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_kelime_secim);
buttonBasla = findViewById(R.id.buttonBasla);
mMediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
fetchAudioUrlFromFirebase();
buttonBasla.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onPrepared(mMediaplayer);
}
});
}
private void fetchAudioUrlFromFirebase() {
final FirebaseStorage storage = FirebaseStorage.getInstance();
// Create a storage reference from our app
StorageReference storageRef = storage.getReferenceFromUrl("MY_URL");
storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
try {
// Download url of file
final String url = uri.toString();
mMediaplayer.setDataSource(url);
// wait for media player to get prepare
mMediaplayer.setOnPreparedListener(null);
mMediaplayer.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(),"Failed",Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
As i said, there is no problem if the audio size low than 50 kb. Actually i'm not sure whether it's because of size. But I tried many files and result is like this.
Upvotes: 1
Views: 823
Reputation: 5042
I am able to reproduce the issue. The files you mentioned do work in other players, but don't work in Android's MediaPlayer
.
The problem files are all encoded at 44000Hz, using libFLAC 1.1.3.
The files that work are all 44100Hz, using libFLAC 1.1.2.
The size correlation appears to be a coincidence. For instance, En-us-you_re2.flac plays fine. It's 166KB, but it's 44100Hz.
It's clear that 44000Hz is a valid rate, but MediaPlayer
simply doesn't support it. You may have better luck with exoplayer with the FLAC extension. Worst case, you might have to find your own decompression library and do the conversion yourself.
Upvotes: 1