Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
Updated 22 April 2017
Playing audios directly without downloading it is an easy and fast way to use media and it also saves device memory. Playing media online also saves you from the headache of management of files in the device.
To stream audios, android provides a class MediaPlayer which is used to play online or offline media files in the app.
You can follow the below code segment and the explanation after that to stream the media directly from the URL.
As you can see in the above code segment that an object of MediaPlayer is created and the url is passed to the function setDataSource().
start() function is used to play the audio file on the URL.
Similarly to play the downloaded audio file. You can follow the below given code segment and the explanation following it.
This is similar to the playing media online except that you need to create() function and pass the file path to the as the parameter.
To perform some task after the completion of audio. you can use the MediaPlayer.OnCompletionListener() function. Check the code segment below
You can also use the isPlaying function to make a single button for play and pause.
Thank you very much, this is Vedesh Kumar signing off.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.