// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v26.3.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")

package io.flutter.plugins.videoplayer

import android.util.Log
import io.flutter.plugin.common.BasicMessageChannel
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MessageCodec
import io.flutter.plugin.common.StandardMessageCodec
import io.flutter.plugin.common.StandardMethodCodec
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer

private object MessagesPigeonUtils {

  fun wrapResult(result: Any?): List<Any?> {
    return listOf(result)
  }

  fun wrapError(exception: Throwable): List<Any?> {
    return if (exception is FlutterError) {
      listOf(exception.code, exception.message, exception.details)
    } else {
      listOf(
          exception.javaClass.simpleName,
          exception.toString(),
          "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception))
    }
  }

  fun doubleEquals(a: Double, b: Double): Boolean {
    // Normalize -0.0 to 0.0 and handle NaN equality.
    return (if (a == 0.0) 0.0 else a) == (if (b == 0.0) 0.0 else b) || (a.isNaN() && b.isNaN())
  }

  fun floatEquals(a: Float, b: Float): Boolean {
    // Normalize -0.0 to 0.0 and handle NaN equality.
    return (if (a == 0.0f) 0.0f else a) == (if (b == 0.0f) 0.0f else b) || (a.isNaN() && b.isNaN())
  }

  fun doubleHash(d: Double): Int {
    // Normalize -0.0 to 0.0 and handle NaN to ensure consistent hash codes.
    val normalized = if (d == 0.0) 0.0 else d
    val bits = java.lang.Double.doubleToLongBits(normalized)
    return (bits xor (bits ushr 32)).toInt()
  }

  fun floatHash(f: Float): Int {
    // Normalize -0.0 to 0.0 and handle NaN to ensure consistent hash codes.
    val normalized = if (f == 0.0f) 0.0f else f
    return java.lang.Float.floatToIntBits(normalized)
  }

  fun deepEquals(a: Any?, b: Any?): Boolean {
    if (a === b) {
      return true
    }
    if (a == null || b == null) {
      return false
    }
    if (a is ByteArray && b is ByteArray) {
      return a.contentEquals(b)
    }
    if (a is IntArray && b is IntArray) {
      return a.contentEquals(b)
    }
    if (a is LongArray && b is LongArray) {
      return a.contentEquals(b)
    }
    if (a is DoubleArray && b is DoubleArray) {
      if (a.size != b.size) return false
      for (i in a.indices) {
        if (!doubleEquals(a[i], b[i])) return false
      }
      return true
    }
    if (a is FloatArray && b is FloatArray) {
      if (a.size != b.size) return false
      for (i in a.indices) {
        if (!floatEquals(a[i], b[i])) return false
      }
      return true
    }
    if (a is Array<*> && b is Array<*>) {
      if (a.size != b.size) return false
      for (i in a.indices) {
        if (!deepEquals(a[i], b[i])) return false
      }
      return true
    }
    if (a is List<*> && b is List<*>) {
      if (a.size != b.size) return false
      val iterA = a.iterator()
      val iterB = b.iterator()
      while (iterA.hasNext() && iterB.hasNext()) {
        if (!deepEquals(iterA.next(), iterB.next())) return false
      }
      return true
    }
    if (a is Map<*, *> && b is Map<*, *>) {
      if (a.size != b.size) return false
      for (entry in a) {
        val key = entry.key
        var found = false
        for (bEntry in b) {
          if (deepEquals(key, bEntry.key)) {
            if (deepEquals(entry.value, bEntry.value)) {
              found = true
              break
            } else {
              return false
            }
          }
        }
        if (!found) return false
      }
      return true
    }
    if (a is Double && b is Double) {
      return doubleEquals(a, b)
    }
    if (a is Float && b is Float) {
      return floatEquals(a, b)
    }
    return a == b
  }

  fun deepHash(value: Any?): Int {
    return when (value) {
      null -> 0
      is ByteArray -> value.contentHashCode()
      is IntArray -> value.contentHashCode()
      is LongArray -> value.contentHashCode()
      is DoubleArray -> {
        var result = 1
        for (item in value) {
          result = 31 * result + doubleHash(item)
        }
        result
      }
      is FloatArray -> {
        var result = 1
        for (item in value) {
          result = 31 * result + floatHash(item)
        }
        result
      }
      is Array<*> -> {
        var result = 1
        for (item in value) {
          result = 31 * result + deepHash(item)
        }
        result
      }
      is List<*> -> {
        var result = 1
        for (item in value) {
          result = 31 * result + deepHash(item)
        }
        result
      }
      is Map<*, *> -> {
        var result = 0
        for (entry in value) {
          result += ((deepHash(entry.key) * 31) xor deepHash(entry.value))
        }
        result
      }
      is Double -> doubleHash(value)
      is Float -> floatHash(value)
      else -> value.hashCode()
    }
  }
}

/**
 * Error class for passing custom error details to Flutter via a thrown PlatformException.
 *
 * @property code The error code.
 * @property message The error message.
 * @property details The error details. Must be a datatype supported by the api codec.
 */
class FlutterError(
    val code: String,
    override val message: String? = null,
    val details: Any? = null
) : RuntimeException()

/** Pigeon equivalent of video_platform_interface's VideoFormat. */
enum class PlatformVideoFormat(val raw: Int) {
  DASH(0),
  HLS(1),
  SS(2);

  companion object {
    fun ofRaw(raw: Int): PlatformVideoFormat? {
      return values().firstOrNull { it.raw == raw }
    }
  }
}

/**
 * Pigeon equivalent of Player's playback state.
 * https://developer.android.com/media/media3/exoplayer/listening-to-player-events#playback-state
 */
enum class PlatformPlaybackState(val raw: Int) {
  IDLE(0),
  BUFFERING(1),
  READY(2),
  ENDED(3),
  UNKNOWN(4);

  companion object {
    fun ofRaw(raw: Int): PlatformPlaybackState? {
      return values().firstOrNull { it.raw == raw }
    }
  }
}

/**
 * Generated class from Pigeon that represents data sent in messages. This class should not be
 * extended by any user class outside of the generated file.
 */
sealed class PlatformVideoEvent
/**
 * Sent when the video is initialized and ready to play.
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class InitializationEvent(
    /** The video duration in milliseconds. */
    val duration: Long,
    /** The width of the video in pixels. */
    val width: Long,
    /** The height of the video in pixels. */
    val height: Long,
    /** The rotation that should be applied during playback. */
    val rotationCorrection: Long
) : PlatformVideoEvent() {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): InitializationEvent {
      val duration = pigeonVar_list[0] as Long
      val width = pigeonVar_list[1] as Long
      val height = pigeonVar_list[2] as Long
      val rotationCorrection = pigeonVar_list[3] as Long
      return InitializationEvent(duration, width, height, rotationCorrection)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        duration,
        width,
        height,
        rotationCorrection,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as InitializationEvent
    return MessagesPigeonUtils.deepEquals(this.duration, other.duration) &&
        MessagesPigeonUtils.deepEquals(this.width, other.width) &&
        MessagesPigeonUtils.deepEquals(this.height, other.height) &&
        MessagesPigeonUtils.deepEquals(this.rotationCorrection, other.rotationCorrection)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.duration)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.width)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.height)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.rotationCorrection)
    return result
  }
}

/**
 * Sent when the video state changes.
 *
 * Corresponds to ExoPlayer's onPlaybackStateChanged.
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class PlaybackStateChangeEvent(val state: PlatformPlaybackState) : PlatformVideoEvent() {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): PlaybackStateChangeEvent {
      val state = pigeonVar_list[0] as PlatformPlaybackState
      return PlaybackStateChangeEvent(state)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        state,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as PlaybackStateChangeEvent
    return MessagesPigeonUtils.deepEquals(this.state, other.state)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.state)
    return result
  }
}

/**
 * Sent when the video starts or stops playing.
 *
 * Corresponds to ExoPlayer's onIsPlayingChanged.
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class IsPlayingStateEvent(val isPlaying: Boolean) : PlatformVideoEvent() {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): IsPlayingStateEvent {
      val isPlaying = pigeonVar_list[0] as Boolean
      return IsPlayingStateEvent(isPlaying)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        isPlaying,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as IsPlayingStateEvent
    return MessagesPigeonUtils.deepEquals(this.isPlaying, other.isPlaying)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.isPlaying)
    return result
  }
}

/**
 * Sent when audio tracks change.
 *
 * This includes when the selected audio track changes after calling selectAudioTrack. Corresponds
 * to ExoPlayer's onTracksChanged.
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class AudioTrackChangedEvent(
    /** The ID of the newly selected audio track, if any. */
    val selectedTrackId: String? = null
) : PlatformVideoEvent() {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): AudioTrackChangedEvent {
      val selectedTrackId = pigeonVar_list[0] as String?
      return AudioTrackChangedEvent(selectedTrackId)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        selectedTrackId,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as AudioTrackChangedEvent
    return MessagesPigeonUtils.deepEquals(this.selectedTrackId, other.selectedTrackId)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.selectedTrackId)
    return result
  }
}

/**
 * Sent when video tracks change.
 *
 * This includes when the selected video track changes after calling selectVideoTrack. Corresponds
 * to ExoPlayer's onTracksChanged.
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class VideoTrackChangedEvent(
    /**
     * The ID of the newly selected video track, if any. Will be null when auto quality selection is
     * enabled.
     */
    val selectedTrackId: String? = null
) : PlatformVideoEvent() {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): VideoTrackChangedEvent {
      val selectedTrackId = pigeonVar_list[0] as String?
      return VideoTrackChangedEvent(selectedTrackId)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        selectedTrackId,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as VideoTrackChangedEvent
    return MessagesPigeonUtils.deepEquals(this.selectedTrackId, other.selectedTrackId)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.selectedTrackId)
    return result
  }
}

/**
 * Information passed to the platform view creation.
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class PlatformVideoViewCreationParams(val playerId: Long) {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): PlatformVideoViewCreationParams {
      val playerId = pigeonVar_list[0] as Long
      return PlatformVideoViewCreationParams(playerId)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        playerId,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as PlatformVideoViewCreationParams
    return MessagesPigeonUtils.deepEquals(this.playerId, other.playerId)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.playerId)
    return result
  }
}

/** Generated class from Pigeon that represents data sent in messages. */
data class CreationOptions(
    val uri: String,
    val formatHint: PlatformVideoFormat? = null,
    val httpHeaders: Map<String, String>,
    val userAgent: String? = null,
    val backBufferDurationMs: Long? = null
) {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): CreationOptions {
      val uri = pigeonVar_list[0] as String
      val formatHint = pigeonVar_list[1] as PlatformVideoFormat?
      val httpHeaders = pigeonVar_list[2] as Map<String, String>
      val userAgent = pigeonVar_list[3] as String?
      val backBufferDurationMs = pigeonVar_list[4] as Long?
      return CreationOptions(uri, formatHint, httpHeaders, userAgent, backBufferDurationMs)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        uri,
        formatHint,
        httpHeaders,
        userAgent,
        backBufferDurationMs,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as CreationOptions
    return MessagesPigeonUtils.deepEquals(this.uri, other.uri) &&
        MessagesPigeonUtils.deepEquals(this.formatHint, other.formatHint) &&
        MessagesPigeonUtils.deepEquals(this.httpHeaders, other.httpHeaders) &&
        MessagesPigeonUtils.deepEquals(this.userAgent, other.userAgent) &&
        MessagesPigeonUtils.deepEquals(this.backBufferDurationMs, other.backBufferDurationMs)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.uri)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.formatHint)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.httpHeaders)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.userAgent)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.backBufferDurationMs)
    return result
  }
}

/** Generated class from Pigeon that represents data sent in messages. */
data class TexturePlayerIds(val playerId: Long, val textureId: Long) {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): TexturePlayerIds {
      val playerId = pigeonVar_list[0] as Long
      val textureId = pigeonVar_list[1] as Long
      return TexturePlayerIds(playerId, textureId)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        playerId,
        textureId,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as TexturePlayerIds
    return MessagesPigeonUtils.deepEquals(this.playerId, other.playerId) &&
        MessagesPigeonUtils.deepEquals(this.textureId, other.textureId)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.playerId)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.textureId)
    return result
  }
}

/** Generated class from Pigeon that represents data sent in messages. */
data class PlaybackState(
    /** The current playback position, in milliseconds. */
    val playPosition: Long,
    /** The current buffer position, in milliseconds. */
    val bufferPosition: Long
) {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): PlaybackState {
      val playPosition = pigeonVar_list[0] as Long
      val bufferPosition = pigeonVar_list[1] as Long
      return PlaybackState(playPosition, bufferPosition)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        playPosition,
        bufferPosition,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as PlaybackState
    return MessagesPigeonUtils.deepEquals(this.playPosition, other.playPosition) &&
        MessagesPigeonUtils.deepEquals(this.bufferPosition, other.bufferPosition)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.playPosition)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.bufferPosition)
    return result
  }
}

/**
 * Represents an audio track in a video.
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class AudioTrackMessage(
    val id: String,
    val label: String,
    val language: String,
    val isSelected: Boolean,
    val bitrate: Long? = null,
    val sampleRate: Long? = null,
    val channelCount: Long? = null,
    val codec: String? = null
) {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): AudioTrackMessage {
      val id = pigeonVar_list[0] as String
      val label = pigeonVar_list[1] as String
      val language = pigeonVar_list[2] as String
      val isSelected = pigeonVar_list[3] as Boolean
      val bitrate = pigeonVar_list[4] as Long?
      val sampleRate = pigeonVar_list[5] as Long?
      val channelCount = pigeonVar_list[6] as Long?
      val codec = pigeonVar_list[7] as String?
      return AudioTrackMessage(
          id, label, language, isSelected, bitrate, sampleRate, channelCount, codec)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        id,
        label,
        language,
        isSelected,
        bitrate,
        sampleRate,
        channelCount,
        codec,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as AudioTrackMessage
    return MessagesPigeonUtils.deepEquals(this.id, other.id) &&
        MessagesPigeonUtils.deepEquals(this.label, other.label) &&
        MessagesPigeonUtils.deepEquals(this.language, other.language) &&
        MessagesPigeonUtils.deepEquals(this.isSelected, other.isSelected) &&
        MessagesPigeonUtils.deepEquals(this.bitrate, other.bitrate) &&
        MessagesPigeonUtils.deepEquals(this.sampleRate, other.sampleRate) &&
        MessagesPigeonUtils.deepEquals(this.channelCount, other.channelCount) &&
        MessagesPigeonUtils.deepEquals(this.codec, other.codec)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.id)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.label)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.language)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.isSelected)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.bitrate)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.sampleRate)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.channelCount)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.codec)
    return result
  }
}

/**
 * Raw audio track data from ExoPlayer Format objects.
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class ExoPlayerAudioTrackData(
    val groupIndex: Long,
    val trackIndex: Long,
    val label: String? = null,
    val language: String? = null,
    val isSelected: Boolean,
    val bitrate: Long? = null,
    val sampleRate: Long? = null,
    val channelCount: Long? = null,
    val codec: String? = null
) {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): ExoPlayerAudioTrackData {
      val groupIndex = pigeonVar_list[0] as Long
      val trackIndex = pigeonVar_list[1] as Long
      val label = pigeonVar_list[2] as String?
      val language = pigeonVar_list[3] as String?
      val isSelected = pigeonVar_list[4] as Boolean
      val bitrate = pigeonVar_list[5] as Long?
      val sampleRate = pigeonVar_list[6] as Long?
      val channelCount = pigeonVar_list[7] as Long?
      val codec = pigeonVar_list[8] as String?
      return ExoPlayerAudioTrackData(
          groupIndex,
          trackIndex,
          label,
          language,
          isSelected,
          bitrate,
          sampleRate,
          channelCount,
          codec)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        groupIndex,
        trackIndex,
        label,
        language,
        isSelected,
        bitrate,
        sampleRate,
        channelCount,
        codec,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as ExoPlayerAudioTrackData
    return MessagesPigeonUtils.deepEquals(this.groupIndex, other.groupIndex) &&
        MessagesPigeonUtils.deepEquals(this.trackIndex, other.trackIndex) &&
        MessagesPigeonUtils.deepEquals(this.label, other.label) &&
        MessagesPigeonUtils.deepEquals(this.language, other.language) &&
        MessagesPigeonUtils.deepEquals(this.isSelected, other.isSelected) &&
        MessagesPigeonUtils.deepEquals(this.bitrate, other.bitrate) &&
        MessagesPigeonUtils.deepEquals(this.sampleRate, other.sampleRate) &&
        MessagesPigeonUtils.deepEquals(this.channelCount, other.channelCount) &&
        MessagesPigeonUtils.deepEquals(this.codec, other.codec)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.groupIndex)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.trackIndex)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.label)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.language)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.isSelected)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.bitrate)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.sampleRate)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.channelCount)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.codec)
    return result
  }
}

/**
 * Container for raw audio track data from Android ExoPlayer.
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class NativeAudioTrackData(
    /** ExoPlayer-based tracks */
    val exoPlayerTracks: List<ExoPlayerAudioTrackData>? = null
) {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): NativeAudioTrackData {
      val exoPlayerTracks = pigeonVar_list[0] as List<ExoPlayerAudioTrackData>?
      return NativeAudioTrackData(exoPlayerTracks)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        exoPlayerTracks,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as NativeAudioTrackData
    return MessagesPigeonUtils.deepEquals(this.exoPlayerTracks, other.exoPlayerTracks)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.exoPlayerTracks)
    return result
  }
}

/**
 * Raw video track data from ExoPlayer Format objects.
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class ExoPlayerVideoTrackData(
    val groupIndex: Long,
    val trackIndex: Long,
    val label: String? = null,
    val isSelected: Boolean,
    val bitrate: Long? = null,
    val width: Long? = null,
    val height: Long? = null,
    val frameRate: Double? = null,
    val codec: String? = null
) {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): ExoPlayerVideoTrackData {
      val groupIndex = pigeonVar_list[0] as Long
      val trackIndex = pigeonVar_list[1] as Long
      val label = pigeonVar_list[2] as String?
      val isSelected = pigeonVar_list[3] as Boolean
      val bitrate = pigeonVar_list[4] as Long?
      val width = pigeonVar_list[5] as Long?
      val height = pigeonVar_list[6] as Long?
      val frameRate = pigeonVar_list[7] as Double?
      val codec = pigeonVar_list[8] as String?
      return ExoPlayerVideoTrackData(
          groupIndex, trackIndex, label, isSelected, bitrate, width, height, frameRate, codec)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        groupIndex,
        trackIndex,
        label,
        isSelected,
        bitrate,
        width,
        height,
        frameRate,
        codec,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as ExoPlayerVideoTrackData
    return MessagesPigeonUtils.deepEquals(this.groupIndex, other.groupIndex) &&
        MessagesPigeonUtils.deepEquals(this.trackIndex, other.trackIndex) &&
        MessagesPigeonUtils.deepEquals(this.label, other.label) &&
        MessagesPigeonUtils.deepEquals(this.isSelected, other.isSelected) &&
        MessagesPigeonUtils.deepEquals(this.bitrate, other.bitrate) &&
        MessagesPigeonUtils.deepEquals(this.width, other.width) &&
        MessagesPigeonUtils.deepEquals(this.height, other.height) &&
        MessagesPigeonUtils.deepEquals(this.frameRate, other.frameRate) &&
        MessagesPigeonUtils.deepEquals(this.codec, other.codec)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.groupIndex)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.trackIndex)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.label)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.isSelected)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.bitrate)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.width)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.height)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.frameRate)
    result = 31 * result + MessagesPigeonUtils.deepHash(this.codec)
    return result
  }
}

/**
 * Container for raw video track data from Android ExoPlayer.
 *
 * Generated class from Pigeon that represents data sent in messages.
 */
data class NativeVideoTrackData(
    /** ExoPlayer-based tracks */
    val exoPlayerTracks: List<ExoPlayerVideoTrackData>? = null
) {
  companion object {
    fun fromList(pigeonVar_list: List<Any?>): NativeVideoTrackData {
      val exoPlayerTracks = pigeonVar_list[0] as List<ExoPlayerVideoTrackData>?
      return NativeVideoTrackData(exoPlayerTracks)
    }
  }

  fun toList(): List<Any?> {
    return listOf(
        exoPlayerTracks,
    )
  }

  override fun equals(other: Any?): Boolean {
    if (other == null || other.javaClass != javaClass) {
      return false
    }
    if (this === other) {
      return true
    }
    val other = other as NativeVideoTrackData
    return MessagesPigeonUtils.deepEquals(this.exoPlayerTracks, other.exoPlayerTracks)
  }

  override fun hashCode(): Int {
    var result = javaClass.hashCode()
    result = 31 * result + MessagesPigeonUtils.deepHash(this.exoPlayerTracks)
    return result
  }
}

private open class MessagesPigeonCodec : StandardMessageCodec() {
  override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
    return when (type) {
      129.toByte() -> {
        return (readValue(buffer) as Long?)?.let { PlatformVideoFormat.ofRaw(it.toInt()) }
      }
      130.toByte() -> {
        return (readValue(buffer) as Long?)?.let { PlatformPlaybackState.ofRaw(it.toInt()) }
      }
      131.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { InitializationEvent.fromList(it) }
      }
      132.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { PlaybackStateChangeEvent.fromList(it) }
      }
      133.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { IsPlayingStateEvent.fromList(it) }
      }
      134.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { AudioTrackChangedEvent.fromList(it) }
      }
      135.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { VideoTrackChangedEvent.fromList(it) }
      }
      136.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let {
          PlatformVideoViewCreationParams.fromList(it)
        }
      }
      137.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { CreationOptions.fromList(it) }
      }
      138.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { TexturePlayerIds.fromList(it) }
      }
      139.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { PlaybackState.fromList(it) }
      }
      140.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { AudioTrackMessage.fromList(it) }
      }
      141.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { ExoPlayerAudioTrackData.fromList(it) }
      }
      142.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { NativeAudioTrackData.fromList(it) }
      }
      143.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { ExoPlayerVideoTrackData.fromList(it) }
      }
      144.toByte() -> {
        return (readValue(buffer) as? List<Any?>)?.let { NativeVideoTrackData.fromList(it) }
      }
      else -> super.readValueOfType(type, buffer)
    }
  }

  override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
    when (value) {
      is PlatformVideoFormat -> {
        stream.write(129)
        writeValue(stream, value.raw.toLong())
      }
      is PlatformPlaybackState -> {
        stream.write(130)
        writeValue(stream, value.raw.toLong())
      }
      is InitializationEvent -> {
        stream.write(131)
        writeValue(stream, value.toList())
      }
      is PlaybackStateChangeEvent -> {
        stream.write(132)
        writeValue(stream, value.toList())
      }
      is IsPlayingStateEvent -> {
        stream.write(133)
        writeValue(stream, value.toList())
      }
      is AudioTrackChangedEvent -> {
        stream.write(134)
        writeValue(stream, value.toList())
      }
      is VideoTrackChangedEvent -> {
        stream.write(135)
        writeValue(stream, value.toList())
      }
      is PlatformVideoViewCreationParams -> {
        stream.write(136)
        writeValue(stream, value.toList())
      }
      is CreationOptions -> {
        stream.write(137)
        writeValue(stream, value.toList())
      }
      is TexturePlayerIds -> {
        stream.write(138)
        writeValue(stream, value.toList())
      }
      is PlaybackState -> {
        stream.write(139)
        writeValue(stream, value.toList())
      }
      is AudioTrackMessage -> {
        stream.write(140)
        writeValue(stream, value.toList())
      }
      is ExoPlayerAudioTrackData -> {
        stream.write(141)
        writeValue(stream, value.toList())
      }
      is NativeAudioTrackData -> {
        stream.write(142)
        writeValue(stream, value.toList())
      }
      is ExoPlayerVideoTrackData -> {
        stream.write(143)
        writeValue(stream, value.toList())
      }
      is NativeVideoTrackData -> {
        stream.write(144)
        writeValue(stream, value.toList())
      }
      else -> super.writeValue(stream, value)
    }
  }
}

val MessagesPigeonMethodCodec = StandardMethodCodec(MessagesPigeonCodec())

/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
interface AndroidVideoPlayerApi {
  fun initialize()

  fun createForPlatformView(options: CreationOptions): Long

  fun createForTextureView(options: CreationOptions): TexturePlayerIds

  fun dispose(playerId: Long)

  fun setMixWithOthers(mixWithOthers: Boolean)

  fun getLookupKeyForAsset(asset: String, packageName: String?): String

  companion object {
    /** The codec used by AndroidVideoPlayerApi. */
    val codec: MessageCodec<Any?> by lazy { MessagesPigeonCodec() }
    /**
     * Sets up an instance of `AndroidVideoPlayerApi` to handle messages through the
     * `binaryMessenger`.
     */
    @JvmOverloads
    fun setUp(
        binaryMessenger: BinaryMessenger,
        api: AndroidVideoPlayerApi?,
        messageChannelSuffix: String = ""
    ) {
      val separatedMessageChannelSuffix =
          if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.AndroidVideoPlayerApi.initialize$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> =
                try {
                  api.initialize()
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.AndroidVideoPlayerApi.createForPlatformView$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val optionsArg = args[0] as CreationOptions
            val wrapped: List<Any?> =
                try {
                  listOf(api.createForPlatformView(optionsArg))
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.AndroidVideoPlayerApi.createForTextureView$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val optionsArg = args[0] as CreationOptions
            val wrapped: List<Any?> =
                try {
                  listOf(api.createForTextureView(optionsArg))
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.AndroidVideoPlayerApi.dispose$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val playerIdArg = args[0] as Long
            val wrapped: List<Any?> =
                try {
                  api.dispose(playerIdArg)
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.AndroidVideoPlayerApi.setMixWithOthers$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val mixWithOthersArg = args[0] as Boolean
            val wrapped: List<Any?> =
                try {
                  api.setMixWithOthers(mixWithOthersArg)
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.AndroidVideoPlayerApi.getLookupKeyForAsset$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val assetArg = args[0] as String
            val packageNameArg = args[1] as String?
            val wrapped: List<Any?> =
                try {
                  listOf(api.getLookupKeyForAsset(assetArg, packageNameArg))
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
    }
  }
}
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
interface VideoPlayerInstanceApi {
  /** Sets whether to automatically loop playback of the video. */
  fun setLooping(looping: Boolean)
  /** Sets the volume, with 0.0 being muted and 1.0 being full volume. */
  fun setVolume(volume: Double)
  /** Sets the playback speed as a multiple of normal speed. */
  fun setPlaybackSpeed(speed: Double)
  /** Begins playback if the video is not currently playing. */
  fun play()
  /** Pauses playback if the video is currently playing. */
  fun pause()
  /** Seeks to the given playback position, in milliseconds. */
  fun seekTo(position: Long)
  /** Returns the current playback position, in milliseconds. */
  fun getCurrentPosition(): Long
  /** Returns the current buffer position, in milliseconds. */
  fun getBufferedPosition(): Long
  /** Gets the available audio tracks for the video. */
  fun getAudioTracks(): NativeAudioTrackData
  /** Selects which audio track is chosen for playback from its [groupIndex] and [trackIndex] */
  fun selectAudioTrack(groupIndex: Long, trackIndex: Long)
  /** Gets the available video tracks for the video. */
  fun getVideoTracks(): NativeVideoTrackData
  /** Selects which video track is chosen for playback from its [groupIndex] and [trackIndex]. */
  fun selectVideoTrack(groupIndex: Long, trackIndex: Long)
  /**
   * Enables automatic video quality selection, allowing the player to adaptively switch between
   * available video tracks based on network conditions.
   */
  fun enableAutoVideoQuality()

  companion object {
    /** The codec used by VideoPlayerInstanceApi. */
    val codec: MessageCodec<Any?> by lazy { MessagesPigeonCodec() }
    /**
     * Sets up an instance of `VideoPlayerInstanceApi` to handle messages through the
     * `binaryMessenger`.
     */
    @JvmOverloads
    fun setUp(
        binaryMessenger: BinaryMessenger,
        api: VideoPlayerInstanceApi?,
        messageChannelSuffix: String = ""
    ) {
      val separatedMessageChannelSuffix =
          if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.setLooping$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val loopingArg = args[0] as Boolean
            val wrapped: List<Any?> =
                try {
                  api.setLooping(loopingArg)
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.setVolume$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val volumeArg = args[0] as Double
            val wrapped: List<Any?> =
                try {
                  api.setVolume(volumeArg)
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.setPlaybackSpeed$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val speedArg = args[0] as Double
            val wrapped: List<Any?> =
                try {
                  api.setPlaybackSpeed(speedArg)
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.play$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> =
                try {
                  api.play()
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.pause$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> =
                try {
                  api.pause()
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.seekTo$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val positionArg = args[0] as Long
            val wrapped: List<Any?> =
                try {
                  api.seekTo(positionArg)
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.getCurrentPosition$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> =
                try {
                  listOf(api.getCurrentPosition())
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.getBufferedPosition$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> =
                try {
                  listOf(api.getBufferedPosition())
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.getAudioTracks$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> =
                try {
                  listOf(api.getAudioTracks())
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.selectAudioTrack$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val groupIndexArg = args[0] as Long
            val trackIndexArg = args[1] as Long
            val wrapped: List<Any?> =
                try {
                  api.selectAudioTrack(groupIndexArg, trackIndexArg)
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.getVideoTracks$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> =
                try {
                  listOf(api.getVideoTracks())
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.selectVideoTrack$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { message, reply ->
            val args = message as List<Any?>
            val groupIndexArg = args[0] as Long
            val trackIndexArg = args[1] as Long
            val wrapped: List<Any?> =
                try {
                  api.selectVideoTrack(groupIndexArg, trackIndexArg)
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
      run {
        val channel =
            BasicMessageChannel<Any?>(
                binaryMessenger,
                "dev.flutter.pigeon.video_player_android.VideoPlayerInstanceApi.enableAutoVideoQuality$separatedMessageChannelSuffix",
                codec)
        if (api != null) {
          channel.setMessageHandler { _, reply ->
            val wrapped: List<Any?> =
                try {
                  api.enableAutoVideoQuality()
                  listOf(null)
                } catch (exception: Throwable) {
                  MessagesPigeonUtils.wrapError(exception)
                }
            reply.reply(wrapped)
          }
        } else {
          channel.setMessageHandler(null)
        }
      }
    }
  }
}

private class MessagesPigeonStreamHandler<T>(val wrapper: MessagesPigeonEventChannelWrapper<T>) :
    EventChannel.StreamHandler {
  var pigeonSink: PigeonEventSink<T>? = null

  override fun onListen(p0: Any?, sink: EventChannel.EventSink) {
    pigeonSink = PigeonEventSink<T>(sink)
    wrapper.onListen(p0, pigeonSink!!)
  }

  override fun onCancel(p0: Any?) {
    pigeonSink = null
    wrapper.onCancel(p0)
  }
}

interface MessagesPigeonEventChannelWrapper<T> {
  open fun onListen(p0: Any?, sink: PigeonEventSink<T>) {}

  open fun onCancel(p0: Any?) {}
}

class PigeonEventSink<T>(private val sink: EventChannel.EventSink) {
  fun success(value: T) {
    sink.success(value)
  }

  fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
    sink.error(errorCode, errorMessage, errorDetails)
  }

  fun endOfStream() {
    sink.endOfStream()
  }
}

abstract class VideoEventsStreamHandler : MessagesPigeonEventChannelWrapper<PlatformVideoEvent> {
  companion object {
    fun register(
        messenger: BinaryMessenger,
        streamHandler: VideoEventsStreamHandler,
        instanceName: String = ""
    ) {
      var channelName: String =
          "dev.flutter.pigeon.video_player_android.VideoEventChannel.videoEvents"
      if (instanceName.isNotEmpty()) {
        channelName += ".$instanceName"
      }
      val internalStreamHandler = MessagesPigeonStreamHandler<PlatformVideoEvent>(streamHandler)
      EventChannel(messenger, channelName, MessagesPigeonMethodCodec)
          .setStreamHandler(internalStreamHandler)
    }
  }
  // Implement methods from MessagesPigeonEventChannelWrapper
  override fun onListen(p0: Any?, sink: PigeonEventSink<PlatformVideoEvent>) {}

  override fun onCancel(p0: Any?) {}
}
