本文介绍了无法解析媒体播放器$ onpreparedlistener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试将播放/暂停/停止添加到存储在资源文件夹中的音频文件

该文件将从webview中的html文件播放。当我尝试将

代码放在一起时,我收到此错误无法解析MediaPlayer $ OnPreparedListener

请参阅下面的代码



@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 $ OnPreparedL istener)new MediaPlayer $ OnPreparedListener(){

public void onPrepared(最终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();

}

}

}

亲切的帮助



我的尝试:



已搜索堆栈溢出

解决方案


OnPreparedListener)新MediaPlayer



HiI 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

解决方案




这篇关于无法解析媒体播放器$ onpreparedlistener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:01