Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am trying to add play/pause/stop to audio file stored in assets folder
the file is to be played from html file in webview. when i tried putting
the code together i am getting this error "cannot resolve MediaPlayer$OnPreparedListener"
see my code below

@JavascriptInterface
public void playAudio(final String s) {
if (this.mp != null) {
if (this.mp.isPlaying()) {
this.mp.pause();
}
else {
this.mp.start();
}
}
else {
try {
final AssetFileDescriptor openFd = this.mContext.getAssets().openFd(s);
(this.mp = new MediaPlayer()).setDataSource(openFd.getFileDescriptor(), openFd.getStartOffset(), openFd.getLength());
openFd.close();
this.mp.prepare();
this.mp.setOnPreparedListener((MediaPlayer$OnPreparedListener)new MediaPlayer$OnPreparedListener() {
public void onPrepared(final MediaPlayer mediaPlayer) {
}
});
this.mp.start();
}
catch (IllegalArgumentException ex) {
Log.e(this.TAG, "Err-1: " + ex.toString());
ex.printStackTrace();
}
catch (IllegalStateException ex2) {
Log.e(this.TAG, "Err-2: " + ex2.toString());
ex2.printStackTrace();
}
catch (IOException ex3) {
Log.e(this.TAG, "Err-3: " + ex3.toString());
ex3.printStackTrace();
}
}
}
Kindly help

What I have tried:

Have searched on stack overflow
Posted
Updated 15-Sep-16 22:16pm

1 solution

try changing

this.mp.setOnPreparedListener((MediaPlayer$OnPreparedListener)new MediaPlayer$OnPreparedListener() {


to

this.mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
 
Share this answer
 
Comments
Member 10627743 16-Sep-16 7:53am    
Thank you Darren_vms

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