Skip to content Skip to sidebar Skip to footer

Sound In Webview

I have a problem with the Playback of Sounds in Webview. I want to play the Sound in the background what is opened by klicking a button. I use at the moment folowwing script, but w

Solution 1:

The code you are writting is to open a new window whenever you will click on link which has .mp3 files in web page

where are your files stored in the app assets or raw or its a url

this is the code for playing file from webview without openning a new window the audio files are stored in raw folder

@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url)
        {         
              if (url.endsWith(".mp3"))  {       
              String temp1=url.replace(".mp3", "");      
              playaudio(temp1);

              returntrue;
        }      
      returntrue;
 } 


       privatevoidplayaudio(String url){
        String s=url;
        int i=getResources().getIdentifier(s,"raw",getPackageName());
        Log.v("name of file",""+s);
        Log.v("id of file",""+i);
        if(i!=0){
        MediaPlayer player = newMediaPlayer().create(getBaseContext(),i);; 
        player.setVolume(0.9f, 0.9f);
        player.start();
        }
    }

Post a Comment for "Sound In Webview"