声音在web视图 [英] Sound in Webview

查看:172
本文介绍了声音在web视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个声音在web视图中播放的一个问题。 我要玩什么地单击一个按钮打开声音的背景。 我目前使用folowwing脚本,但是当我点击到一个新的窗口被打开按钮。

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 when i click to the button a new window is opened.

package C.K;

import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;

final class MyWebViewClient extends WebViewClient {
    @Override     
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {         
        if (url.endsWith(".mp3"))  {             
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse(url), "audio/*");
            view.getContext().startActivity(intent);

            return true;
            } else {
                return super.shouldOverrideUrlLoading(view, url);
                }     } } 

谁能帮我?

推荐答案

在code你书面方式就是打开一个新窗口 只要你会点击链接,有 在网页的.mp3文件

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

在哪里都存储在应用程序文件 资产或生或它的一个url

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

这是在code播放从web视图文件,而不开扩新窗口 音频文件存储在原文件夹

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

       @Override     
         public boolean shouldOverrideUrlLoading(WebView view, String url)
        {         
              if (url.endsWith(".mp3"))  {       
              String temp1=url.replace(".mp3", "");      
              playaudio(temp1);

              return true;
        }      
      return true;
 } 


       private  void playaudio(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 = new MediaPlayer().create(getBaseContext(),i);; 
        player.setVolume(0.9f, 0.9f);
        player.start();
        }
    }

这篇关于声音在web视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆