Android 媒体播放器在流彩信协议时停止播放?

发布于 2024-10-02 18:46:36 字数 2767 浏览 0 评论 0原文

我的 Android 应用程序使用 AudioTrack 类通过 MMS 流播放广播,如下所述 此处

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

这是可能有用的 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();
}

My android application plays a radio through MMS Stream using AudioTrack class as described here

The Problem is that after playing first chunk the device doesn't get any audio output.

Here is the logcat info that may be useful

 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

Here is the code (It's the method itself which called periodically from C code)

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();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文