Android TV播放器在PlaybackTransportRowPresenter.createRowViewHolder上出现膨胀错误

6qftjkof  于 2023-04-18  发布在  Android
关注(0)|答案(2)|浏览(86)

我在扩展“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: TypedValue{t=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)

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

yx2lnoni

yx2lnoni1#

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

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

yhuiod9q2#

无论是谁在寻找这个问题的解决方案,vahid aghakhani's answer都是正确的。谢谢。
您还可以通过在清单android:theme="@style/Theme.Leanback"中添加主题来实现此目的

相关问题