偶尔会收到“处理调优请求的时间太长”错误

时间:2016-02-12 04:58:09

标签: android android-tv exoplayer

我已经构建了一个Android TV直播频道应用,一般来说效果很好。但有时,我会收到用户的崩溃报告,该报告给出了如下错误:

02-11 13:32:21.135 29165-29165/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.felkertech.sample.channelsurfer, PID: 29165
    java.lang.RuntimeException: Too much time to handle tune request. (2160ms > 2000ms) Consider handling the tune request in a separate thread.
    at android.media.tv.ITvInputSessionWrapper.executeMessage(ITvInputSessionWrapper.java:166)
    at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

我真的不知道如何解决这个问题,因为错误没有引用我的任何代码。此外,我无法一致地重现此错误。

以下是我的onTune方法的一部分。请注意,它确实从另一个类调用一个方法来实际获取视频:

    @Override
public boolean onTune(Uri channelUri) {
    notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING);
    setOverlayViewEnabled(true);
    Log.d(TAG, "Tuning to " + channelUri.toString());
    String[] projection = {TvContract.Channels.COLUMN_DISPLAY_NAME, TvContract.Channels.COLUMN_ORIGINAL_NETWORK_ID,
            TvContract.Channels.COLUMN_SERVICE_ID, TvContract.Channels.COLUMN_TRANSPORT_STREAM_ID,
            TvContract.Channels.COLUMN_INPUT_ID, TvContract.Channels.COLUMN_DISPLAY_NUMBER};
    //Now look up this channel in the DB
    try (Cursor cursor = tvInputProvider.getContentResolver().query(channelUri, projection, null, null, null)) {
        if (cursor == null || cursor.getCount() == 0) {
            return false;
        }
        cursor.moveToNext();
        Channel channel = new Channel()
                .setNumber(cursor.getString(cursor.getColumnIndex(TvContract.Channels.COLUMN_DISPLAY_NUMBER)))
                .setName(cursor.getString(cursor.getColumnIndex(TvContract.Channels.COLUMN_DISPLAY_NAME)))
                .setOriginalNetworkId(cursor.getInt(cursor.getColumnIndex(TvContract.Channels.COLUMN_ORIGINAL_NETWORK_ID)))
                .setTransportStreamId(cursor.getInt(cursor.getColumnIndex(TvContract.Channels.COLUMN_TRANSPORT_STREAM_ID)))
                .setServiceId(cursor.getInt(cursor.getColumnIndex(TvContract.Channels.COLUMN_SERVICE_ID)))
                .setVideoHeight(1080)
                .setVideoWidth(1920);
        this.currentChannel = channel;
        TvInputManager mTvInputManager = (TvInputManager) tvInputProvider.getApplicationContext().getSystemService(Context.TV_INPUT_SERVICE);
        if(mTvInputManager.isParentalControlsEnabled()) {
            TvContentRating blockedRating = null;
            for(int i=0;i<tvInputProvider.getProgramRightNow(channel).getContentRatings().length;i++) {
                blockedRating = (mTvInputManager.isRatingBlocked(tvInputProvider.getProgramRightNow(channel).getContentRatings()[i]) && blockedRating == null)?tvInputProvider.getProgramRightNow(channel).getContentRatings()[i]:null;
            }
            if(blockedRating != null) {
                notifyContentBlocked(blockedRating);
            }
        }
        notifyContentAllowed();
        return tvInputProvider.onTune(channel);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

tvInputPlayer.onTune

public boolean onTune(Channel channel) {
    this.currentChannel = channel;
    this.lastTune = new Date();
    Toast.makeText(SampleTvInputProvider.this, "Tuning to "+channel.getName()+" with program "+getProgramRightNow(channel).getTitle()+" at "+getProgramRightNow(channel).getInternalProviderData(), Toast.LENGTH_SHORT).show();
    Log.d(TAG, "Tuning to " + channel.getName());
    Log.d(TAG, "Playing "+getProgramRightNow(channel).getTitle());
    Log.d(TAG, "Play the video "+getProgramRightNow(channel).getInternalProviderData());

    //Only my local channels will have the ability to be time shifted, so I should update that every tuning.
    //Timeshifting only works for API >= 23
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (isLocal()) {
            getSession().notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
        } else {
            //If it's not a local channel, I cannot pause or seek in the program
            getSession().notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_UNAVAILABLE);
        }
    }

    play(getProgramRightNow(channel).getInternalProviderData());
    if(currentChannel.getNumber().equals("4")) {
        Handler h = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                setOverlayEnabled(true);
            }
        };
        h.sendEmptyMessageDelayed(0, 16);
    }
    return true;
}

方法play在ExoPlayer中加载URL。我觉得这可能是缓冲会导致ExoPlayer稍微滞后以产生这个问题的地方,但我不知道如何解决这个问题。

有人知道吗?

感谢。

1 个答案:

答案 0 :(得分:1)

我最近遇到了类似的问题,并通过计时代码块将其隔离到查询:

tvInputProvider.getContentResolver().query(.....

如果您的频道是第一个经过调整的频道,则在启动Live Channels应用时,此查询有时会超过2秒。 我删除了查询(通过保留自己的表)并避免了问题。