Stagefright媒体延迟2.2设置数据源后? [英] Stagefright media delay in 2.2 after setting data source?

查看:240
本文介绍了Stagefright媒体延迟2.2设置数据源后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一篇文章在这里。这个网站已经成为Android的学习编程非常有用,感谢大家。

My first post here. This website has been very useful for learning Android programming, thanks to everyone.

我有一个加载MP3流并播放一个简单的应用程序。它工作正常的1.6和2.1,但2.2上没有引起太大工作的权利。看来我的服务有问题出发,它给我的ANR,并在那里我必须点击等待的对话框,然后最后是服务启动。为什么走的是服务很长时间才能启动?

I have a simple app that loads an MP3 stream and plays it. It works fine on 1.6 and 2.1 but on 2.2 it doesn't quite work right. It seems my service is having a problem starting, it's giving my an ANR and the dialog where I have to tap "Wait", and then finally the service starts. Why is the service taking a long time to start up?

下面是我简单的code,设置源和播放音频:

Here's my simple code that sets the source and plays the audio:

    public class MyActivityService extends Service {

 MediaPlayer player = new MediaPlayer();

 @Override
 public IBinder onBind(Intent intent) {
  return null;
 }
 @Override
 public void onCreate() {  
  super.onCreate();   

  try {

   player.setDataSource("URL OF MUSIC FILE");
  } catch (IllegalArgumentException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IllegalStateException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

  try {

   player.prepare();
   player.setVolume(1, 1);
      player.setLooping(true);           
      player.start();                   

   Toast.makeText(getApplicationContext(), "Audio Service Started.", Toast.LENGTH_SHORT).show();}

附录:

原来这不是我的服务没有启动,它是不是在2.2快速启动足够的音频...

Turns out it wasn't my service not starting, it's the audio that's not starting quickly enough in 2.2...

我摆脱了ANR次数的时候,我的服务启动和停止通过把的onCreate()的onDestroy()我在自己的线程服务,这可能是它应该是如何从一开始的方法呢?对不起,只是学习。

I got rid of the ANRs when my service started and stopped by putting the onCreate() and onDestroy() methods of my service in their own threads, which is probably how it should have been from the beginning? Sorry, just learning.

但是,这是真正的问题迟迟仍然存在,澄清 -

But the delay that's the real problem remains, to clarify --

例如,我的code,因为它是现在,做工精细和花花公子,只是我多么希望它在2.1和2.2时,我的数据源设置为MP3文件是这样的: HTTP ://dl.dropbox.com/u/6916184/TestSongStream.mp3

For example, my code, as it is right now, works fine and dandy and just how I want it to in 2.1 AND 2.2 when I set the data source to an MP3 file like this: http://dl.dropbox.com/u/6916184/TestSongStream.mp3

但是当我的数据源设置为一个像这样的音频流的位置: http://d.liveatc.net/kjfk_twr 或本 HTTP://relay.radioreference。 COM:192236577分之80它工作正常只有2.1。

BUT when I set the data source to an audio stream location like this: http://d.liveatc.net/kjfk_twr or this: http://relay.radioreference.com:80/192236577 it works correctly ONLY in 2.1.

在2.2的声音也开始播放最后,但它直到音频开始,如下所示设置数据源后,以StagefrightPlayer约25秒左右的:

In 2.2 the sound does start playing eventually, but it takes "StagefrightPlayer" about 25 seconds or so after setting the data source until the audio starts as shown here:

07-31 02:54:30.176: INFO/StagefrightPlayer(34): setDataSource('http://relay.radioreference.com:80/192236577')
07-31 02:54:55.228: INFO/AwesomePlayer(34): calling prefetcher->prepare()
07-31 02:54:56.231: INFO/Prefetcher(34): [0x2cc28] cache below low water mark, filling cache.
07-31 02:54:56.337: INFO/AwesomePlayer(34): prefetcher is done preparing
07-31 02:54:56.347: DEBUG/AudioSink(34): bufferCount (4) is too small and increased to 12
07-31 02:54:57.337: ERROR/AwesomePlayer(34): Not sending buffering status because duration is unknown.

这也需要同样多的时间,约25秒,以停止媒体播放器后, player.stop()是所谓的我的服务,并在的onDestroy()法的onDestroy()方法继续上敬酒的消息,并取消通知。

It also takes the same amount of time, about 25 seconds, to stop the media player after player.stop() is called in the onDestroy() method of my service, and the onDestroy() method continues on to Toast a message and cancel a notification.

是现在的样子是2.2?如果是这样,我可以工作延迟身边,这不是一个问题。或者更有可能的是什么事情我做错了吗?但是,它的工作原理正是我想在1.6和2.1!

Is that just the way it is with 2.2? If so, I can work around the delays, that's not a problem. Or more likely is it something I am doing wrong? But it works exactly as I want in 1.6 and 2.1!

应该张贴更多code帮助?

Would posting more code help?

我的code是非常简单的。没有音响控制之类的东西。只是一个开始音频按钮,停止音频按钮启动和停止播放音频流的服务。

My code is very simple. There are no audio controls or anything like that. Simply a start audio button and stop audio button that start and stop a service that plays an audio stream.

感谢您的帮助!

推荐答案

不要叫 prepare()从主应用程序线程,特别是对于一个流,因为这可能需要更长的时间比你的ANR之前已获准。使用 prepareAsync()来代替。我不知道如果这是您的特定问题的根源,但肯定会在你的当前实现的ANR的原因之一。

Do not call prepare() from the main application thread, particularly for a stream, because that may take much longer than you're allowed before an ANR. Use prepareAsync() instead. I have no idea if that is the root of your particular problem, but it would certainly be one cause of an ANR in your current implementation.

这篇关于Stagefright媒体延迟2.2设置数据源后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆