I am working on Android, I am creating a player for audio songs. I want to play a song in just 30 seconds. After that, the player must be closed. It should start again if I press the START button again.
This is the code to create a media player:
MediaPlayer mediaPlayer = new MediaPlayer(); public void songPreview(String songURL){ try{ mediaPlayer=new MediaPlayer(); mediaPlayer.setDataSource(songURL); mediaPlayer.prepare(); mediaPlayer.start(); } catch(Exception ex){ ex.printStackTrace(); } }
Please suggest me which code should be used to play my song only for 30 seconds, after which it will stop, and if I want to play again, then I have to press the start button.
Note. Please provide me the logic to stop the media player after 30 seconds.
Thanks in advance.
source share