this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

android clean

Hailey de6347cd ef932f1a

+39 -20
+8 -4
android/src/main/java/expo/modules/blueskyvideo/BlueskyVideoModule.kt
··· 40 40 41 41 View(BlueskyVideoView::class) { 42 42 Events( 43 - "onStatusChange", 44 - "onMutedChange", 45 - "onTimeRemainingChange", 43 + "onActiveChange", 46 44 "onLoadingChange", 47 - "onActiveChange", 45 + "onMutedChange", 48 46 "onPlayerPress", 47 + "onStatusChange", 48 + "onTimeRemainingChange", 49 49 "onError", 50 50 ) 51 51 ··· 55 55 56 56 Prop("autoplay") { view: BlueskyVideoView, prop: Boolean -> 57 57 view.autoplay = prop 58 + } 59 + 60 + Prop("beginMuted") { view: BlueskyVideoView, prop: Boolean -> 61 + view.beginMuted = prop 58 62 } 59 63 60 64 AsyncFunction("togglePlayback") { view: BlueskyVideoView ->
+31 -16
android/src/main/java/expo/modules/blueskyvideo/BlueskyVideoView.kt
··· 26 26 @UnstableApi 27 27 class BlueskyVideoView(context: Context, appContext: AppContext) : ExpoView(context, appContext) { 28 28 private val playerScope = CoroutineScope(Job() + Dispatchers.Main) 29 + 29 30 private val playerView: PlayerView 30 31 var player: ExoPlayer? = null 32 + 31 33 private var progressTracker: ProgressTracker? = null 32 34 33 35 var url: Uri? = null 34 - 35 36 var autoplay = false 37 + var beginMuted = true 36 38 37 39 private var isFullscreen: Boolean = false 38 40 set(value) { ··· 77 79 )) 78 80 } 79 81 80 - private val onStatusChange by EventDispatcher() 81 - private val onLoadingChange by EventDispatcher() 82 82 private val onActiveChange by EventDispatcher() 83 - private val onTimeRemainingChange by EventDispatcher() 83 + private val onLoadingChange by EventDispatcher() 84 84 private val onMutedChange by EventDispatcher() 85 - private val onError by EventDispatcher() 86 85 private val onPlayerPress by EventDispatcher() 86 + private val onStatusChange by EventDispatcher() 87 + private val onTimeRemainingChange by EventDispatcher() 88 + private val onError by EventDispatcher() 89 + 90 + private var enteredFullscreenMuteState = true 87 91 88 92 init { 89 93 val playerView = PlayerView(context).apply { ··· 106 110 107 111 // Lifecycle 108 112 109 - private fun playVideo() { 113 + private fun setup() { 114 + // We shouldn't encounter this scenario, but would rather be safe than sorry here and just 115 + // skip setup if we do. 110 116 if (this.player != null) { 111 117 return 112 118 } ··· 122 128 } 123 129 } 124 130 125 - private fun removeVideo() { 131 + private fun destroy() { 126 132 val player = this.player ?: return 127 133 128 134 this.mute() ··· 171 177 this.player?.volume = 0f 172 178 this.isMuted = true 173 179 } 174 - 175 180 private fun unmute() { 176 181 this.player?.volume = 1f 177 182 this.isMuted = false 178 183 } 179 - 180 184 fun toggleMuted() { 181 185 if (this.isMuted) { 182 186 unmute() ··· 188 192 fun enterFullscreen() { 189 193 val currentActivity = this.appContext.currentActivity ?: return 190 194 195 + this.enteredFullscreenMuteState = this.isMuted 196 + 197 + // We always want to start with unmuted state and playing. Fire those from here so the 198 + // event dispatcher gets called 191 199 this.unmute() 192 200 if (!this.isPlaying) { 193 201 this.play() ··· 207 215 208 216 fun onExitFullscreen() { 209 217 this.isFullscreen = false 210 - this.mute() 218 + if (this.enteredFullscreenMuteState) { 219 + this.mute() 220 + } 211 221 if(autoplay) { 212 222 this.play() 213 223 } else { ··· 225 235 226 236 this.isViewActive = isActive 227 237 if (isActive) { 228 - this.playVideo() 238 + this.setup() 229 239 } else { 230 - this.removeVideo() 240 + this.destroy() 231 241 } 232 242 return true 233 243 } ··· 253 263 val totalArea = this.width * this.height 254 264 return visibleArea >= 0.5 * totalArea 255 265 } 266 + 267 + // Setup helpers 256 268 257 269 private suspend fun createMediaItem(): MediaItem { 258 270 return withContext(Dispatchers.IO) { ··· 271 283 } 272 284 .build().apply { 273 285 repeatMode = ExoPlayer.REPEAT_MODE_ALL 274 - volume = 0f 286 + if (beginMuted) { 287 + volume = 0f 288 + } 275 289 addListener(object : Player.Listener { 276 290 override fun onPlaybackStateChanged(playbackState: Int) { 277 291 when (playbackState) { 278 292 ExoPlayer.STATE_READY -> { 279 - if (this@BlueskyVideoView.autoplay) { 280 - this@BlueskyVideoView.isLoading = false 281 - this@BlueskyVideoView.play() 293 + val view = this@BlueskyVideoView 294 + if (view.autoplay) { 295 + view.isLoading = false 296 + view.play() 282 297 } 283 298 } 284 299 }