Open PierreEc opened 1 year ago
CR Kot001 CR Swift001
Rule name: Videos and media content should not be preloaded
Tickets existant dans le kanban
Type of consumption: Network requests, Battery drain, CPU/GPU
Sometimes useless or interrompt user Easy implementable
Example:
struct VideoView: View {
@State var player = AVPlayer(url: ***)
var body: some View {
VideoPlayer(player: player)
.frame(width: 400, height: 300, alignment: .center)
.onAppear {
player.play()
}
}
}
OS | OS version | Langage. |
---|---|---|
iOS/iPadOS/WatchOS/tvOS - Android | - | Swift / Kotlin |
ID | Title | Category | Sub-category |
---|---|---|---|
- | Environment | Optimized API |
Severity | Remediation Cost |
---|---|
Medium | Minor |
When you use native player, you can play the player on avent like onAppear/onLoad on apple platform or onDispose onandroid platform
When you use native player, you can play the player on avent like onAppear/onLoad on apple platform or onDispose on android platform
<p>When you use native player, you can play the player on avent like onAppear/onLoad on apple platform or onDispose on android platform</p>
<p>
<pre>
struct VideoView: View {
@State var player = AVPlayer(url: ***)
var body: some View {
VideoPlayer(player: player)
.frame(width: 400, height: 300, alignment: .center)
.onAppear {
player.play()
}
}
}
</pre>
Clever idea. I've been wondering for a while how to detect video autoplay. This bad practice has a big impact.
Lorsque l'on utilise le player native, et qu'on lance la méthode play dans une action comme onAppear, onDispose ou autre
https://developer.apple.com/documentation/avfoundation/avplayer/1386726-play https://developer.android.com/reference/android/media/MediaPlayer#start()