当前位置: 动力学知识库 > 问答 > 编程问答 >

html - audio doesnt get played on android 4.3 through webview which load url using android asset

问题描述:

I am not able to play the mp3 file from the android application which has a webview in which i am calling the html page

This is my main activity file

package com.example.dsspunjab;

import android.os.Bundle;

import android.app.Activity;

import android.content.Context;

import android.content.Intent;

import android.view.Menu;

import android.webkit.WebView;

import android.widget.ImageButton;

import android.view.View;

import android.view.View.OnClickListener;

public class MainActivity extends Activity implements OnClickListener{

ImageButton button1, button2;

ImageButton button3;

WebView brows, brows1;

final Context context = this;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

button1 = (ImageButton) findViewById(R.id.imageButton1);

button1.setOnClickListener(this);

button2 = (ImageButton) findViewById(R.id.imageButton2);

button2.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

setContentView(R.layout.screen2);

button3 = (ImageButton) findViewById(R.id.button1);

brows1=(WebView) findViewById(R.id.webView1);

brows1.getSettings().setJavaScriptEnabled(true);

brows1.loadUrl("file:///android_asset/App1/index.html");

button3.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

Intent intent = new Intent(context, MainActivity.class);

startActivity(intent);

}

});

}

});

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

@Override

public void onClick(View view) {

setContentView(R.layout.screen1);

button3 = (ImageButton) findViewById(R.id.button1);

brows=(WebView) findViewById(R.id.webView1);

brows.getSettings().setJavaScriptEnabled(true);

brows.loadUrl("file:///android_asset/App/index.html");

button3.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

Intent intent = new Intent(context, MainActivity.class);

startActivity(intent);

}

});

}

}

this is the html code snippet where i am calling the mp3,

"

 <div class="modal-body">

<!-- <img src="images/paddy_varieties/click-detail-punjab-basmati-2.png" data-elem="pinchzoomer" alt="img1"/> -->

<audio msAudioCategory="BackgroundCapableMedia" controls="controls">

<source src="images/paddy_varieties/VN_Normal_1.mp3" class="mp3"/>

</audio>

</div>

<div class="modal-footer">

<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>

</div>

</div>

"

I am able to play the video on the html page viewed through the web browser (google chrome) but not through the android application.

分享给朋友:
您可能感兴趣的文章:
随机阅读: