Android媒体播放器在流式传输mms协议时停止播放?

时间:2010-11-12 05:58:30

标签: android streaming

我的Android应用程序使用AudioTrack类通过MMS Stream播放收音机,如here

所述

问题是在播放第一个块后,设备无法获得任何音频输出。

以下是可能有用的logcat信息

 DEBUG/WifiService(1904): ACTION_BATTERY_CHANGED pluggedType: 2
11-12 11:21:07.953: INFO/Hello(2821): There
11-12 11:21:07.958: INFO/Get Current Player State(2821): 3
11-12 11:21:07.958: INFO/Paused(2821): 2
11-12 11:21:07.958: INFO/Playing(2821): 3
11-12 11:21:07.958: INFO/Stopped(2821): 1
11-12 11:21:07.963: INFO/Size(2821): 7864364
11-12 11:21:08.023: DEBUG/dalvikvm(2821): GC freed 103 objects / 4184 bytes in 62ms
11-12 11:21:08.078: INFO/dalvikvm-heap(2821): Grow heap (frag case) to 14.770MB for 7864380-byte allocation
11-12 11:21:08.153: DEBUG/dalvikvm(2821): GC freed 0 objects / 0 bytes in 74ms
11-12 11:21:08.273: ERROR/AudioPolicyManager(1868): [HJ] isDuplicated = 0 
11-12 11:21:08.273: ERROR/AudioPolicyManager(1868): 1.[HJ] Headset Volume = 0.354813 , device = 4
11-12 11:21:08.273: INFO/Offset(2821): 11837528

这是代码(它是从C代码定期调用的方法本身)

boolean b = false;
Log.i("Hello", "There");
if (at != null) {
    Log.i("Comparing", "" + at.getPlayState());
    Log.i("Paused", "" + AudioTrack.PLAYSTATE_PAUSED);
    Log.i("Playing", "" + AudioTrack.PLAYSTATE_PLAYING);
    Log.i("Stopped", "" + AudioTrack.PLAYSTATE_STOPPED);

    b = at.getPlayState() != AudioTrack.PLAYSTATE_PLAYING;
}
try {
    if (!b) {
        int intSize = android.media.AudioTrack.getMinBufferSize(33075,
                AudioFormat.CHANNEL_CONFIGURATION_STEREO,
                AudioFormat.ENCODING_PCM_16BIT);
        at = new AudioTrack(AudioManager.STREAM_MUSIC, 33075,
                AudioFormat.CHANNEL_CONFIGURATION_STEREO,
                AudioFormat.ENCODING_PCM_16BIT, intSize * 20,
                AudioTrack.MODE_STREAM);
    }
    if (at == null) {
        Log.d("TCAudio", "audio track is not initialised ");
        return;
    }

    // 512 kb
    // Reading the file..
    byte[] byteData = null;
    if (file == null)
        file = new File("/sdcard/outmms.wav");
    int size = (int) file.length();

    Log.i("Size", "" + size);

    byteData = new byte[size];
    FileInputStream in = null;
    try {
        in = new FileInputStream(file);
        in.read(byteData);

        // if (!b) {
        at.play();
        // }
        at.write(byteData, offset, byteData.length);
        offset += byteData.length;
        Log.i("Offset", "" + offset);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
} catch (Exception e) {
    e.printStackTrace();
}

0 个答案:

没有答案