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.