Связывание данных с сторонними библиотеками - PullRequest
0 голосов
/ 07 марта 2020

Я создаю приложение, в котором можно просматривать списки фильмов и смотреть трейлер. Я использую сторонний проигрыватель YouTube и привязку данных, вот мой xml код

<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">


<data>
    <variable
        name="videoID"
        type="String"
        />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".views.TrailerActivity">


    <com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
        android:id="@+id/trailer_player"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:videoId="@={videoID}"
        app:autoPlay="true"
        app:showFullScreenButton="false" />

    <Button
        android:id="@+id/play_trailer_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/play"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/trailer_player" />

</androidx.constraintlayout.widget.ConstraintLayout>

Вот мой TrailerActivity

package com.decagon.moviehut.views

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import com.decagon.moviehut.R
import com.decagon.moviehut.controllers.repositories.URLRepository
import com.decagon.moviehut.databinding.ActivityTrailerBinding
import com.decagon.moviehut.viewmodels.TrailerViewModel
import com.google.android.youtube.player.YouTubeBaseActivity
import com.google.android.youtube.player.YouTubeInitializationResult
import com.google.android.youtube.player.YouTubePlayer
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener
//import com.google.android.youtube.player.YouTubePlayerView
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
import kotlinx.android.synthetic.main.activity_trailer.*
    import kotlin.properties.Delegates

class TrailerActivity : AppCompatActivity() {

    private lateinit var playerView: YouTubePlayerView
    private lateinit var viewModel: TrailerViewModel
    private lateinit var player: YouTubePlayer

    private lateinit var binding: ActivityTrailerBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_trailer)

        playerView = findViewById<YouTubePlayerView>(R.id.trailer_player)
        viewModel = TrailerViewModel(this.application)
        val id = intent.getIntExtra("movie_id", 0)
        val videoID = viewModel.getKey(id)

        lifecycle.addObserver(playerView);

        binding.videoID = videoID

        playerView.addYouTubePlayerListener(object: AbstractYouTubePlayerListener(){
            override fun onReady(youTubePlayer: com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer) {
               // youTubePlayer.loadVideo(videoID, 0f)
            }
        })

    }
}

Когда я пытаюсь для сборки я получаю следующую ошибку сборки

> Task :app:kaptDebugKotlin
ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1C:\Users\HP\Documents\Android Studio Projects\Kotlin\MovieHut\app\build\generated\source\kapt\debug\com\decagon\moviehut\DataBinderMapperImpl.java:9: error: cannot find symbol
import com.decagon.moviehut.databinding.ActivityTrailerBindingImpl;
                                       ^
  symbol:   class ActivityTrailerBindingImpl

> Task :app:kaptDebugKotlin FAILED
  location: package com.decagon.moviehut.databinding
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
   > java.lang.reflect.InvocationTargetException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Я подозреваю, что проблема может быть из-за взаимодействия между привязкой данных и проигрывателем YouTube

1 Ответ

0 голосов
/ 07 марта 2020

Здесь вы можете найти правильный ответ ..

Как использовать kotlin .Int в привязке данных?

Пожалуйста, проверьте эту ссылку !!

...