我已经在我的代码中实现了webviewclient来访问我的android代码中的一些html内容。我在shouldInterceptRequest()方法中给出了条件来获取mp3文件的调用,以便可以在运行时进行更改。在第一天,它已成功实现,但现在该方法从未调用我尚未更改代码的mp3文件,但仍然无法到达我做错的地方
我的HTML文件存储在本地,现在我已经手动存储了,但是将从php服务器下载。我的已实现WebView客户端在下面
myWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
MSLogger.msLogD("initSleave", "WebViewClient: " + url + "\nview: " + view);
view.loadUrl(url);
return true;
}
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String request) {
if (request.contains(".mp3")) {
if (prefs.getLanguage().equalsIgnoreCase("Hi")) {
try {
request= request.replace(".mp3", "_hindi.mp3");
request=request.replace("file://","");
return new WebResourceResponse("audio/mp3", "UTF-8", new FileInputStream(request));
} catch (Exception e) {
e.printStackTrace();
}
}
}
return super.shouldInterceptRequest(view, request);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Log.d("RequestView", "----->" + request);
return super.shouldOverrideUrlLoading(view, request);
}
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
Log.d("RequestView", "----->" + request);
return super.shouldInterceptRequest(view, request);
}
});
我想让网络客户端何时调用Sleave(Html)内容中提到的mp3资源文件。但是它现在只调用所有png,ttf,css和xmls
答案 0 :(得分:0)
.mp3的MIME类型参数应更改为audio / mpeg
= O