【问题标题】:Android WebView resize default audio playerAndroid WebView 调整默认音频播放器的大小
【发布时间】:2017-03-24 02:27:01
【问题描述】:

我在我的应用程序中使用 webview,我给它一个音频 url。

它在某些设备上工作得非常好。看下面的截图:

但在某些设备中,它看起来并不友好。

有没有办法设置 webview 音频播放器的大小?

更新:代码 sn-p:

//打开DOI活动

Intent podcastIntent = new Intent(mContext, DoiWebActivity.class);
podcastIntent.setAction(Constants.INTENT_VIEW_LINK);
podcastIntent.putExtra(Constants.EXTRA_DOI_LINK_URL, podcasts.get(0).getPodcastLink());
        podcastIntent.putExtra(Constants.CALLING_FRAGMENT,Constants.CALLING_FRAGMENT_PODCAST_LISTING);
        podcastIntent.putExtra(Constants.EXTRA_PODCAST_NAME,mContext.getString(R.string.podcast));

mContext.startActivity(podcastIntent);

//从 podcastListingFragment 调用:播客名称

       if (bundle != null && bundle.containsKey(Constants.CALLING_FRAGMENT) &&
                bundle.containsKey(Constants.EXTRA_PODCAST_NAME)) {

String title = bundle.getString(SilverChairConstants.EXTRA_PODCAST_NAME);

             }
if (Utility.isNetworkAvailable(mActivity)) {
            /**
             * Showing external link.
             */
            mWebView.loadUrl(mIntentText);

        } else {

            networkNotAvailable();

        }

xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    tools:context=".fragments.WebFragment">

    <WebView
        android:layout_below="@+id/toolbar"
        android:id="@+id/wv_webcontainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!--progress bar-->
    <include layout="@layout/silverchair_progress"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignTop="@id/wv_webcontainer"
        android:layout_alignBottom="@id/wv_webcontainer"/>


    <include layout="@layout/empty_view"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_centerInParent="true"
        />

</RelativeLayout>

【问题讨论】:

  • 分享你的代码sn-p
  • 已添加。 @VikashKumarVerma 请检查
  • 编写与 webview 及其布局相关的代码。
  • 添加了@VikashKumarVerma

标签: android audio webview


【解决方案1】:

在初始化 webview 的代码中添加这一行。 mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);

如果您已经这样做了,我建议您使用 MediaPlayer 进行 straming。

    MediaPlayer mediaPlayer = MediaPlayer.create(this, Uri.parse("http://vprbbc.streamguys.net:80/vprbbc24.mp3"));
mediaPlayer.start(); 

有关 MediaPlayer 流式传输的更多详细信息,请参阅此answer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多