Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everyone
I followed this tutorial Playing Audio on Android from an HTML5 File[^] on this forum and it working well can
someone kindly help on how add pause/stop/play buttons.
An answer will be appreciated
Thanks in advance

What I have tried:

I have tried searching on google and adding the image myself
Posted
Updated 17-Jul-16 2:02am

1 solution

MediaPlayer | Android Developers[^]
This control has stop() and pause() methods too...Use them in your click even handler...
 
Share this answer
 
Comments
Member 10627743 17-Jul-16 8:51am    
Peter thank you for the reply but i tried the code below but still the button controls are not working

HTML
<div class="clear">
<button >Play Some Audio</button>
<br>
<button >Play Some Audio</button>
<br>
<button >Play Some Audio</button>

</div>

AudioInterface
//Pause an audio file from the webpage
@JavascriptInterface
public void pauseAudio(String aud) { //String aud - file name passed
//from the JavaScript function
final MediaPlayer mp;

try {
AssetFileDescriptor fileDescriptor =
mContext.getAssets().openFd(aud);
mp = new MediaPlayer();
mp.setDataSource(fileDescriptor.getFileDescriptor(),
fileDescriptor.getStartOffset(),
fileDescriptor.getLength());
fileDescriptor.close();
mp.prepare();
mp.pause();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Can you give an idea of how to implement this properly
Kornfeld Eliyahu Peter 17-Jul-16 9:00am    
You should not create a new audio player, but find and use the exciting one...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900