I am new android developer , trying to play local sdcard mp3 file in WebView .
help me.
I want to add sound in android web view application.
( The sound should be play when click a button in the screen.)
My html application worked in the browser.
But not worked in android.I don’t know why?
WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview=(WebView)findViewById(R.id.webview);
et_Url=(EditText)findViewById(R.id.et_Url);
btn_Go=(Button)findViewById(R.id.btn_Go);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file:///android_asset/test.html");
}
//asset file
test.html
test.mp3
//html source code
<audio id="sample" src="file:///android_asset/test.mp3" controls preload></audio>
<a href="javascript:playSegment(0.5);">Play2</a>
<script>
var audio = document.getElementById('sample');
var segmentEnd;
function playSegment(startTime, endTime){
segmentEnd = endTime;
audio.currentTime = startTime;
audio.play();
}
</script>
I am solve my problem this way .. I hope this will be helpful to you…