WARN/AudioFlinger(33):写入阻塞 76 毫秒,7773 次延迟写入,线程 0xb3f0

发布于 2024-12-04 09:11:14 字数 2254 浏览 0 评论 0原文

我创建了一个意向服务来在后台启动我的应用程序的音乐。

它正在工作,但我的日志猫充满了消息:

09-14 16:46:30.117: WARN/AudioFlinger(33): write blocked for 76 msecs, 7773elasted writes, thread 0xb3f0 并且没有其他内容被记录。

这是我的 IntentService:

import android.app.IntentService;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.widget.Toast;

public class MusicService extends IntentService {

    MediaPlayer mPlayer;
    private OnErrorListener mErrorListener;

    public MusicService() {
        super("MusicService");
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        // TODO Auto-generated method stub
          // Normally we would do some work here, like download a file.


    }   

    ///////////////////////////////////////////////////////////

    @Override
    public int onStartCommand (Intent intent, int flags, int startId)

    {
        Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
        mPlayer.setLooping(true);
        mPlayer.start();

        return super.onStartCommand(intent,flags,startId);


    }

    @Override

    public void onCreate ()

    {
        super.onCreate();
      //  try{
            mPlayer = MediaPlayer.create(this, R.raw.jingle);
        //}catch (IllegalArgumentException e) {
            //e.printStackTrace();
        //}catch (IllegalStateException e ) {
            //e.printStackTrace();
        //}

        if(mPlayer!= null)
        {
            mPlayer.setLooping(true); // Set looping
            mPlayer.setVolume(100,100);
        }


    mPlayer.setOnErrorListener(new OnErrorListener() {

        public boolean onError(MediaPlayer mp, int what, int extra) {
            // TODO Auto-generated method stub
            onPlayError();
            return true;
        }

    });


    }

    private void onPlayError() {
        Toast.makeText(this, "music player failed", Toast.LENGTH_SHORT).show(); 
        if(mPlayer != null)
        {
            try{
                mPlayer.stop();
                mPlayer.release();
            }finally {
                mPlayer = null;
            }
        }
    }

I have created an intent service to start the music for my app in the background.

It is working, but my log-cat is flooded with the messages:

09-14 16:46:30.117: WARN/AudioFlinger(33): write blocked for 76 msecs, 7773 delayed writes, thread 0xb3f0
and nothing else is getting Logged.

Here is my IntentService:

import android.app.IntentService;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.widget.Toast;

public class MusicService extends IntentService {

    MediaPlayer mPlayer;
    private OnErrorListener mErrorListener;

    public MusicService() {
        super("MusicService");
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        // TODO Auto-generated method stub
          // Normally we would do some work here, like download a file.


    }   

    ///////////////////////////////////////////////////////////

    @Override
    public int onStartCommand (Intent intent, int flags, int startId)

    {
        Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
        mPlayer.setLooping(true);
        mPlayer.start();

        return super.onStartCommand(intent,flags,startId);


    }

    @Override

    public void onCreate ()

    {
        super.onCreate();
      //  try{
            mPlayer = MediaPlayer.create(this, R.raw.jingle);
        //}catch (IllegalArgumentException e) {
            //e.printStackTrace();
        //}catch (IllegalStateException e ) {
            //e.printStackTrace();
        //}

        if(mPlayer!= null)
        {
            mPlayer.setLooping(true); // Set looping
            mPlayer.setVolume(100,100);
        }


    mPlayer.setOnErrorListener(new OnErrorListener() {

        public boolean onError(MediaPlayer mp, int what, int extra) {
            // TODO Auto-generated method stub
            onPlayError();
            return true;
        }

    });


    }

    private void onPlayError() {
        Toast.makeText(this, "music player failed", Toast.LENGTH_SHORT).show(); 
        if(mPlayer != null)
        {
            try{
                mPlayer.stop();
                mPlayer.release();
            }finally {
                mPlayer = null;
            }
        }
    }

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

调妓 2024-12-11 09:11:15

需要权限。将这些放入 AndroidManifest.xml 中:

<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />

我在 android 模拟器 2.2 下测试了它,所以我的 minSdkVersion 是 8。

Permissions are needed. Put these in AndroidManifest.xml:

<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />

I tested it under android emulator 2.2 so my minSdkVersion is 8.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文