Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:06:40+00:00 2026-06-13T18:06:40+00:00

I am new android developer , trying to play local sdcard mp3 file in

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:06:41+00:00Added an answer on June 13, 2026 at 6:06 pm

    I am solve my problem this way .. I hope this will be helpful to you…

    //asset folder
       test.html
       // test.html html source code 
         <a href="test.mp3">Play</a>
    //raw folder contains following file
      test.mp3
        WebView  webview;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            webview=(WebView)findViewById(R.id.webview);
            webview.setWebViewClient(new MyWebViewClient());
            webview.getSettings().setJavaScriptEnabled(true);
            webview.loadUrl("file:///android_asset/test.html");
        }
         class MyWebViewClient extends WebViewClient {
    
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                     playaudio();
                     return true;
            }
    
    
        }
           private  void playaudio(){
               int i=R.raw.test;
                Log.v("id of file",""+i);
                if(i!=0){
                MediaPlayer player = new MediaPlayer().create(getBaseContext(),i);; 
                player.setVolume(0.9f, 0.9f);
                player.start();
                }
           }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to android development. I'm trying to have my string.xml file add
I am a new android app developer and i want to use google map
I am new android app developer i want make app for tablets and phone
I'm new in android development and I am trying out the WebView example in
I'm trying to authorize the Google Play Android Developer API. I'm at the step
I am a new android developer trying to write a simple contact book. When
I am a new android developer. I was trying to install eclipse in my
I am a new android developer trying to code a widget.. The updatePeriodMillis parameter
i am new to android programming and i am trying to develop an app
I am new to android programming and i am trying to develop this app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.