媒体播放器中的logcat警告突然停止:TimedEventQueue(33):事件4没有在队列中找到,已经取消了?队列、媒体播放、器中、突然

2023-09-06 18:19:10 作者:﹏删除シ记忆

我试图把背景音乐在我的app.I创造它创建了一个媒体播放器,并开始音乐的目的服务。

在我的应用程序推出的音乐只打了一秒钟之后,我看到我的logcat以下警告: -

20 09-13:12:54.082:WARN / TimedEventQueue(33):事件4在队列中没有被发现,已取消

有关我的应用程序的每一次运行时,事件数changes.This一次是事件5.

Android 中Logcat的使用

下面是实现媒体播放器,我的服务类: -

 进口android.app.IntentService;进口android.content.Intent;进口android.media.MediaPlayer;进口android.media.MediaPlayer.OnErrorListener;进口android.widget.Toast;公共类MusicService扩展IntentService {    MediaPlayer的MPLAYER;    私人OnErrorListener mErrorListener;    公共MusicService(){        超级(MusicService);        // TODO自动生成构造函数存根    }    @覆盖    保护无效onHandleIntent(意向意图){        // TODO自动生成方法存根          //通常我们会在这里做了一些工作,比如要下载的文件。    }    ////////////////////////////////////////////////// /////////    @覆盖    公众诠释onStartCommand(意向意图,诠释旗帜,INT startId)    {        Toast.makeText(这一点,服务启动,Toast.LENGTH_SHORT).show();        mPlayer.setLooping(真);        mPlayer.start();        返回super.onStartCommand(意向,旗帜,startId);    }    @覆盖    公共无效的onCreate()    {        super.onCreate();      //尝试{            MPLAYER = MediaPlayer.create(这一点,R.raw.jingle);        //}赶上(抛出:IllegalArgumentException五){            //e.printStackTrace();        //}赶上(IllegalStateException异常五){            //e.printStackTrace();        //}        如果(MPLAYER!= NULL)        {            mPlayer.setLooping(真); //设置循环            mPlayer.setVolume(100,100);        }    mPlayer.setOnErrorListener(新OnErrorListener(){        公共布尔的onError(MediaPlayer的熔点,诠释了什么,整型附加){            // TODO自动生成方法存根            onPlayError();            返回true;        }    });    }    私人无效onPlayError(){        Toast.makeText(这一点,音乐播放器失败,Toast.LENGTH_SHORT).show();        如果(MPLAYER!= NULL)        {            尝试{                mPlayer.stop();                mPlayer.release();            } {最后                MPLAYER = NULL;            }        }    }    @覆盖    公共无效的onDestroy()    {        super.onDestroy();        如果(MPLAYER!= NULL)        {            尝试{                mPlayer.stop();                mPlayer.release();            } {最后                MPLAYER = NULL;            }        }    }} 

解决方案

我得到了solution.The问题是,由于我使用一个Intent服务,因此,意图在启动服务后,玩家开始了,但马上就销毁被称为那里是一个code释放和停止播放。

去除code之后,我可以看到音乐连续播放而且我没有看到那些定时队列警告!!!

I am trying to put background music in my app.I have created an intent service which creates a Media Player and starts the music.

Once my app is launched the music is played only for a second and after that I see the following warning in my logcat:-

09-13 20:12:54.082: WARN/TimedEventQueue(33): Event 4 was not found in the queue, already cancelled?

For every run of my App, the Event number changes.This time it was Event 5.

Here is my service class which implements media player:-

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

    @Override
    public void onDestroy ()

    {
        super.onDestroy();
        if(mPlayer != null)
        {
            try{
                mPlayer.stop();
                mPlayer.release();
            }finally {
                mPlayer = null;
            }
        }

    }



}

解决方案

I got the solution.The problem was that since I am using an Intent service, so after starting the service with an intent, the player started but immediately on Destroy was called where there is a code to release and stop the player.

After removing that code I could see the music playing continuously and moreover I did not see those timed queue warnings!!!

 
精彩推荐
图片推荐