Skip to content

Commit

Permalink
Make player animations smoother (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
defagos authored Jan 6, 2024
1 parent 4c04c49 commit f28eac7
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 28 deletions.
14 changes: 5 additions & 9 deletions Demo/Sources/Players/PlaybackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private struct MainView: View {
.supportsPictureInPicture(supportsPictureInPicture)
}
}
.animation(.easeInOut(duration: 0.2), values: player.mediaType, player.isExternalPlaybackActive)
.animation(.easeIn(duration: 0.2), values: player.mediaType, player.isExternalPlaybackActive)
}

@ViewBuilder
Expand Down Expand Up @@ -478,15 +478,11 @@ private struct PlaybackButton: View {
if player.canReplay() {
return "arrow.counterclockwise.circle.fill"
}
else if player.rate == 0 {
return "play.circle.fill"
}
else {
switch player.playbackState {
case .playing:
return "pause.circle.fill"
case .paused:
return "play.circle.fill"
default:
return nil
}
return "pause.circle.fill"
}
}

Expand Down
2 changes: 1 addition & 1 deletion Demo/Sources/Players/SimplePlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct SimplePlayerView: View {
@ViewBuilder
private func playbackButton() -> some View {
Button(action: player.togglePlayPause) {
Image(systemName: player.playbackState == .playing ? "pause.circle.fill" : "play.circle.fill")
Image(systemName: player.rate == 0 ? "play.circle.fill" : "pause.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50)
Expand Down
2 changes: 1 addition & 1 deletion Demo/Sources/Showcase/Multi/SingleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct SingleView: View {
@ViewBuilder
private func playbackButton(player: Player) -> some View {
Button(action: player.togglePlayPause) {
Image(systemName: player.playbackState == .playing ? "pause.circle.fill" : "play.circle.fill")
Image(systemName: player.rate == 0 ? "play.circle.fill" : "pause.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50)
Expand Down
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,11 @@ struct PlayerView: View {
item: .simple(url: URL(string: "https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8")!)
)

private var buttonImage: String {
switch player.playbackState {
case .playing:
return "pause.circle.fill"
default:
return "play.circle.fill"
}
}

var body: some View {
ZStack {
VideoView(player: player)
Button(action: player.togglePlayPause) {
Image(systemName: buttonImage)
Image(systemName: player.rate == 0 ? "play.circle.fill" : "pause.circle.fill")
.resizable()
.frame(width: 80, height: 80)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct ContentView: View {
ZStack {
VideoView(player: player)
Button(action: player.togglePlayPause) {
Image(systemName: player.playbackState == .playing ? "pause.circle.fill" : "play.circle.fill")
Image(systemName: player.rate == 0 ? "play.circle.fill" : "pause.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct ContentView: View {
VideoView(player: player)
HStack(spacing: 20) {
Button(action: player.togglePlayPause) {
Image(systemName: player.playbackState == .playing ? "pause.circle.fill" : "play.circle.fill")
Image(systemName: player.rate == 0 ? "play.circle.fill" : "pause.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct ContentView: View {
.frame(width: 30)
}
Button(action: player.togglePlayPause) {
Image(systemName: player.playbackState == .playing ? "pause.circle.fill" : "play.circle.fill")
Image(systemName: player.rate == 0 ? "play.circle.fill" : "pause.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct ContentView: View {
.frame(width: 30)
}
Button(action: player.togglePlayPause) {
Image(systemName: player.playbackState == .playing ? "pause.circle.fill" : "play.circle.fill")
Image(systemName: player.rate == 0 ? "play.circle.fill" : "pause.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct ContentView: View {
.frame(width: 30)
}
Button(action: player.togglePlayPause) {
Image(systemName: player.playbackState == .playing ? "pause.circle.fill" : "play.circle.fill")
Image(systemName: player.rate == 0 ? "play.circle.fill" : "pause.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ContentView: View {
.frame(width: 30)
}
Button(action: player.togglePlayPause) {
Image(systemName: player.playbackState == .playing ? "pause.circle.fill" : "play.circle.fill")
Image(systemName: player.rate == 0 ? "play.circle.fill" : "pause.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ContentView: View {
.frame(width: 30)
}
Button(action: player.togglePlayPause) {
Image(systemName: player.playbackState == .playing ? "pause.circle.fill" : "play.circle.fill")
Image(systemName: player.rate == 0 ? "play.circle.fill" : "pause.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50)
Expand Down

0 comments on commit f28eac7

Please sign in to comment.