1

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.

Community
  • 1
  • 1
Teber Ms
  • 41
  • 1
  • I'm not to sure it's because of the size, either. More likely the 44000 sample rate. I've never even heard of that. Should be 44100. – greeble31 Jan 07 '19 at 02:36
  • Well, what can i do to fix this error? – Teber Ms Jan 08 '19 at 10:39
  • How do you know that the larger audio files are valid to begin with? Do they play in other players? Can you post one here? – greeble31 Jan 08 '19 at 17:03
  • @greeble31 I tried different audio files from an another source and they play fine. And I got some informations about 'sample rate'. As far as i understand if I can change the number of sample rate maybe it will play. Do you have information about changing sample rate? – Teber Ms Jan 10 '19 at 20:46
  • "I tried different audio files from an another source and they play fine" <-- yes, but this only verifies your player is working. It doesn't help us determine if your audio files are valid. Assuming you are allowed to modify the files, it is possible to change the sample rate, but this is an extreme operation, and should only be undertaken if you can identify the reason the files were mastered with the wrong sample rate to begin with. Are they corrupt? Where did they come from? – greeble31 Jan 10 '19 at 21:07
  • The audios are English words pronunciations files. And i got them from this site : http://shtooka.net/download.php (Wikimedia Commons - Pronunciation (eng-wcp-us)) And they normally play smoothly but if I try to play in Android Studio-MediaPlayer, I get this error. – Teber Ms Jan 11 '19 at 13:32
  • These work fine on my API 28 emulator. Can you indicate one specific file that does not work, so we can evaluate that as a test case? – greeble31 Jan 11 '19 at 14:45
  • En-us-rigid.flac, En-us-achieve.flac, En-us-geology.flac in Wikimedia Commons - Pronunciation (eng-wcp-us) I've tried to play on my API 28 emulator, also on my phone API 25 but result is same. – Teber Ms Jan 11 '19 at 16:09

1 Answers1

1

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.

greeble31
  • 4,894
  • 2
  • 16
  • 30