Android TV 播放器在 PlaybackTransportRowPresenter.createRowViewHolder 上充气错误

Posted

技术标签:

【中文标题】Android TV 播放器在 PlaybackTransportRowPresenter.createRowViewHolder 上充气错误【英文标题】:Android TV player inflating error on PlaybackTransportRowPresenter.createRowViewHolder 【发布时间】:2020-06-29 08:07:18 【问题描述】:

我在扩展“VideoSupportFragment”的片段中编写了波纹管代码

val playerGlue = PlaybackTransportControlGlue(
                activity,
                MediaPlayerAdapter(activity))
        playerGlue.setHost(VideoSupportFragmentGlueHost(this))
        playerGlue.addPlayerCallback(object : PlaybackGlue.PlayerCallback() 
            override fun onPreparedStateChanged(glue: PlaybackGlue) 
                if (glue.isPrepared()) 
                    //playerGlue.seekProvider = MySeekProvider()
                    playerGlue.play()
                
            
        )
        playerGlue.playerAdapter?.setDataSource(Uri.parse("http://techslides.com/demos/sample-videos/small.mp4"))

当调用 setHost 时,应用程序崩溃并且 logcat 中出现以下日志。

如果我评论 setHost,则只播放音频。

2020-03-15 02:32:15.578 1779-1779/tv.debug E/androidRuntime: FATAL EXCEPTION: main
    Process: tv.debug, PID: 1779
    android.view.InflateException: Binary XML file line #33: Binary XML file line #33: Error inflating class <unknown>
    Caused by: android.view.InflateException: Binary XML file line #33: Error inflating class <unknown>
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at android.view.LayoutInflater.createView(LayoutInflater.java:645)
        at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at androidx.leanback.widget.PlaybackTransportRowPresenter.createRowViewHolder(PlaybackTransportRowPresenter.java:684)
        at androidx.leanback.widget.RowPresenter.onCreateViewHolder(RowPresenter.java:326)
        at androidx.leanback.widget.ItemBridgeAdapter.onCreateViewHolder(ItemBridgeAdapter.java:352)
        at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7078)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6235)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
        at androidx.leanback.widget.GridLayoutManager.getViewForPosition(GridLayoutManager.java:1085)
        at androidx.leanback.widget.GridLayoutManager$2.createItem(GridLayoutManager.java:1613)
        at androidx.leanback.widget.SingleRow.appendVisibleItems(SingleRow.java:113)
        at androidx.leanback.widget.Grid.appendOneColumnVisibleItems(Grid.java:389)
        at androidx.leanback.widget.GridLayoutManager.appendOneColumnVisibleItems(GridLayoutManager.java:1839)
        at androidx.leanback.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:2276)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
        at androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1897)
        at androidx.recyclerview.widget.RecyclerView$1.run(RecyclerView.java:414)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
        at android.view.Choreographer.doCallbacks(Choreographer.java:686)
        at android.view.Choreographer.doFrame(Choreographer.java:618)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 68: TypedValuet=0x2/d=0x7f04005d a=-1
        at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:716)
        at android.view.View.<init>(View.java:4228)
        at android.view.ViewGroup.<init>(ViewGroup.java:579)
        at android.widget.LinearLayout.<init>(LinearLayout.java:211)
        at android.widget.LinearLayout.<init>(LinearLayout.java:207)
2020-03-15 02:32:15.578 1779-1779/com.shatelland.namava.tv.debug E/AndroidRuntime:     at android.widget.LinearLayout.<init>(LinearLayout.java:203)

我不知道为什么这个类是未知的。 因此,我找不到哪个布局有错误。

【问题讨论】:

【参考方案1】:

经过长时间的搜索,我找到了原因。 包含 Fragment 的 Activity 应将主题设置为 Leanback

override fun onCreate(savedInstanceState: Bundle?) 
    super.onCreate(savedInstanceState)
    setTheme(R.style.Theme_Leanback)

【讨论】:

以上是关于Android TV 播放器在 PlaybackTransportRowPresenter.createRowViewHolder 上充气错误的主要内容,如果未能解决你的问题,请参考以下文章

Android TV 播放器在 PlaybackTransportRowPresenter.createRowViewHolder 上充气错误

在 Android TV 上升级 Android WebView 后,hls 264 视频不再播放

Android TV 从 URL 播放视频

如何在 PlaybackTransportControlGlue android TV 上动态更改字幕

通知不会出现在 Android TV 上

Android TV 中的 ExoPlayer 以纵向模式而不是横向模式播放视频