简体   繁体   English

MediaPlayer()音频口吃(android)

[英]MediaPlayer() audio stuttering(android)

I am using the MediaPlayer function to stream a live audio stream from a remote server, in my android app. 我在我的Android应用程序中使用MediaPlayer功能从远程服务器流式传输实时音频流。 But the audio is choppy and stuttering. 但音频不稳定且口吃。 The problem is not my internet as the feed plays perfectly when I play it on the computer. 问题不在于我的互联网,因为当我在计算机上播放时,Feed会完美播放。 What could be the problem?*Note: the streams are live. 可能是什么问题?*注意:流是实时的。 This is the code I'm using: 这是我正在使用的代码:

MediaPlayer mp = new MediaPlayer();
    try{
    mp.setDataSource("http://radiotool:80/feed 342.mp3");//hardcoded for testing purposes
    mp.prepare();
    mp.start();
    }
    catch(Exception e)
    {Log.d("Error came up man",", check the internet connection and stuff..");

The stream you are linking to is not sending a large buffer of data at the beginning of the stream. 您链接到的流不是在流的开头发送大的数据缓冲区。 Normally this is not a problem, as the client is responsible for determining the rate of playback, watching the data transfer rate, and managing a client-side buffer accordingly. 通常这不是问题,因为客户端负责确定回放速率,观察数据传输速率以及相应地管理客户端缓冲区。 That is why when I gave you a link to try that does use a large buffer, this wasn't a problem to play. 这就是为什么当我给你一个尝试使用大缓冲区的链接时,这不是一个问题。

Basically, the audio dropouts are due to constant buffer underruns. 基本上,音频丢失是由于恒定的缓冲区欠载。 To fix this, you need to increase the buffer size. 要解决此问题,您需要增加缓冲区大小。 It seems this isn't possible right now, but another method may be to manage the HTTP client yourself and proxy the data to the MediaPlayer . 现在看来这是不可能的,但另一种方法可能是自己管理HTTP客户端并将数据代理到MediaPlayer That link is quite old... hopefully someone has figured out how to do this another way since then. 这个链接很老了......希望有人从那时起就想出了如何以另一种方式做到这一点。 I am not an Android developer, so I cannot tell you for sure. 我不是Android开发人员,所以我无法肯定地告诉你。

What I would do first is call mp.prepareAsync() , and wait 2 seconds after the MediaPlayer tells you that it is ready to start. 我首先要做的是调用mp.prepareAsync() ,并在MediaPlayer告诉你它已准备好启动后等待2秒。 I have a hunch that data will continue to buffer in the background until you actually call .start() . 我有预感,数据将继续在后台缓冲,直到您实际调用.start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM