How do I loop my Media Player files?

前端 未结 1 1125
南方客
南方客 2021-01-19 11:55

Basically I have 3 songs, and I want the user to be able to loop back to the first song once the cycle of 3 songs is complete. Why won\'t this work? It will play all 3 songs

1条回答
  •  再見小時候
    2021-01-19 12:36

    Call the function:

    MediaPlayer.setLooping(true|false)

    on the mediaplayerObject after you called MediaPlayer.prepare()

    Example:

    Uri mediaUri = createUri(context, R.raw.media); // Audiofile in raw folder
    Mediaplayer mPlayer = new MediaPlayer();
    mPlayer.setDataSource(context, mediaUri);
    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mPlayer.prepare();
    
    mPlayer.setLooping(true);
    
    mPlayer.start();
    

    0 讨论(0)
提交回复
热议问题