小编Jer*_*man的帖子

Android的MediaPlayer为什么需要这么长时间来准备播放的实时流?

我发现Android MediaPlayer准备使用不同的流进行实时流播放所花费的时间差异很大.

硬数据

我在prepareAsync()和onPrepared(MediaPlayer mp)回调之间添加了日志记录,并且每次都测试了几个流.每个流的时间非常一致(+/- 1秒),结果如下:

  1. MPR新闻流:27秒(http://newsstream1.publicradio.org:80/)
  2. MPR古典音乐流:15秒(http://classicalstream1.publicradio.org:80/)
  3. MPR当前流:7秒(http://currentstream1.publicradio.org:80/)
  4. PRI流:52秒(http://pri-ice.streamguys.biz/pri1)

测试是在带有Android 2.3.4的Nexus S上进行的3G连接(~1100 Kbps).

播放非流式MP3音频文件不是问题.

以下是我如何播放流的片段:

准备MediaPlayer:

...
mediaPlayer.setDataSource(playUrl);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepareAsync();
...
Run Code Online (Sandbox Code Playgroud)

然后在onPrepared(MediaPlayer mp):

mediaPlayer.start();
Run Code Online (Sandbox Code Playgroud)

为什么要准备一些流而不是其他流需要这么长时间?上述数据似乎表明它可能基于已缓冲的数据而不是缓冲的音频内容的持续时间.真的可以吗?

更新:我已经使用Android 1.6,2.2和2.3.4以及1.6,2.1,2.2,2.3.1和2.3.3的仿真器测试了物理设备上的实时流媒体.我只看到2.3.3和2.3.4的长时间延迟.旧版本在5秒内开始播放.

audio streaming android audio-streaming android-mediaplayer

48
推荐指数
3
解决办法
2万
查看次数

我如何处理Android问题9161,其中bottomRightRadius和bottomLeftRadius被交换?

我的目标:

图1:目标
图1:目标

所以,在我知道这个问题之前,这就是我尝试过的.

一,基础布局:

<LinearLayout
    android:orientation="horizontal"
    android:layout_below="@id/heading"
    android:layout_marginTop="10dp"
    android:layout_width="@dimen/horizontal_two_button_width"
    android:layout_height="@dimen/button_height_small" >

    <Button
        android:id="@+id/button_one"
        android:layout_width="0dp"
        android:layout_weight="1.0"
        android:layout_height="fill_parent"
        android:padding="10dp"
        style="@style/ButtonText"
        android:background="@drawable/button_left_green" />

    <Button
        android:id="@+id/button_two"
        android:layout_width="0dp"
        android:layout_weight="1.0"
        android:layout_height="fill_parent"
        android:padding="10dp"
        style="@style/ButtonText"
        android:background="@drawable/button_right_green" />      

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

'button_left_green'drawable:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_left_green_pressed"
        android:state_pressed="true" />
    <item android:drawable="@drawable/button_left_green_focused"
        android:state_focused="true" />
    <item android:drawable="@drawable/button_left_green_default" />
</selector>
Run Code Online (Sandbox Code Playgroud)

并且,例如,'button_left_green_default'drawable:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/shadow" />
            <corners
                android:radius="5dp"
                android:topLeftRadius="5dp"
                android:topRightRadius="0dp"
                android:bottomLeftRadius="5dp"
                android:bottomRightRadius="0dp" />      
        </shape>
    </item>
    <item
        android:bottom="19dp"
        android:top="1dp"
        android:left="1dp"
        android:right="1dp" >

        <shape android:shape="rectangle">
            <gradient
                android:startColor="@color/button_left_green_top_gradient_start"
                android:endColor="@color/button_left_green_top_gradient_end" …
Run Code Online (Sandbox Code Playgroud)

android rounded-corners

18
推荐指数
2
解决办法
8566
查看次数

WebSettings的LOAD_DEFAULT和LOAD_NORMAL有什么区别?

我有一个WebView活动,想要缓存内容.默认情况下,它似乎不使用缓存.

Android的WebSettings有几个不同的缓存相关常量.

当我将缓存模式设置为"LOAD_CACHE_ELSE_NETWORK"时,它似乎使用缓存.但是,我不想使用过期的缓存内容.

这让我使用:

  1. LOAD_DEFAULT:"默认缓存使用模式"或
  2. LOAD_NORMAL:"正常缓存使用模式"

但文档没有详细说明"正常"和"默认"的含义.

这两种模式有何不同?

android webview android-webview

10
推荐指数
1
解决办法
3259
查看次数