Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio for Videos #1490

Merged
merged 12 commits into from
Dec 11, 2024
Prev Previous commit
Next Next commit
merge dev
  • Loading branch information
EricBAndrews committed Dec 9, 2024
commit 3e5e9038928d6b882f308954836b5b5108d3826f
1 change: 1 addition & 0 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -331,6 +331,7 @@
CD5581DE2C7B8B820043FAC3 /* ImageFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5581DD2C7B8B820043FAC3 /* ImageFunctions.swift */; };
CD57AFA32D03761500AB3956 /* WebpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD57AFA22D03761300AB3956 /* WebpView.swift */; };
CD57AFA52D0377EB00AB3956 /* AnimationControlLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD57AFA42D0377E400AB3956 /* AnimationControlLayer.swift */; };
CD5F3F452D06167F008C55D5 /* MlemMiddleware in Frameworks */ = {isa = PBXBuildFile; productRef = CD5F3F442D06167F008C55D5 /* MlemMiddleware */; };
CD635E1B2C94DACD00864F75 /* BypassProxyWarningSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD635E1A2C94DACD00864F75 /* BypassProxyWarningSheet.swift */; };
CD64A91A2CA37E8D007CA7E6 /* Gifu in Frameworks */ = {isa = PBXBuildFile; productRef = CD64A9192CA37E8D007CA7E6 /* Gifu */; };
CD64A91C2CA38DBA007CA7E6 /* NukeWebpBridgeDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD64A91B2CA38DA7007CA7E6 /* NukeWebpBridgeDecoder.swift */; };
14 changes: 11 additions & 3 deletions Mlem/App/Views/Shared/Images/Core/Animated/VideoView.swift
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ struct VideoView: View {
let player: AVPlayer

@State var animating: Bool = true
@State var soundOn: Bool

init(asset: AVAsset) {
do {
@@ -22,19 +23,26 @@ struct VideoView: View {
print(error)
}
player = .init(playerItem: .init(asset: asset))
player.isMuted = true

player.isMuted = false
self._soundOn = .init(wrappedValue: true)

player.play()
}

var body: some View {
VideoPlayer(player: player)
.disabled(true)
.onChange(of: animating, initial: true) {
.onChange(of: animating, initial: false) {
if animating {
player.play()
} else {
player.pause()
}
}
.withAnimationControls(animating: $animating)
.onChange(of: soundOn, initial: false) {
player.isMuted = !soundOn
}
.withAnimationControls(animating: $animating, soundOn: $soundOn)
}
}
5 changes: 1 addition & 4 deletions Mlem/App/Views/Shared/Images/Core/DynamicMediaView.swift
Original file line number Diff line number Diff line change
@@ -105,6 +105,7 @@ struct DynamicMediaView: View {
}
.onTapGesture {
if viewerEnabled, let url = loader.url, loader.loading == .done {
playing = false
showViewer(url: url)
}
}
@@ -116,10 +117,6 @@ struct DynamicMediaView: View {
await loader.load()
}
}
.onDisappear {
playing = false
}
#if DEBUG
.overlay {
if developerMode, let ext = loader.url?.proxyAwarePathExtension?.uppercased() {
Text(ext)
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import SwiftUICore

private struct AnimationControlLayer: ViewModifier {
@Binding var animating: Bool
var soundOn: Binding<Bool>?

func body(content: Content) -> some View {
content
@@ -21,15 +22,35 @@ private struct AnimationControlLayer: ViewModifier {
} else {
Color.clear.contentShape(.rect)
.onTapGesture {
print("DEBUG tapped here")
animating = false
}
}
}
.overlay(alignment: .topTrailing) {
if let soundOn {
Image(systemName: soundOn.wrappedValue ? "speaker.wave.2.fill" : "speaker.slash.fill")
.resizable()
.scaledToFit()
.frame(width: 15, height: 15)
.padding(5)
.background {
Circle().foregroundStyle(.ultraThinMaterial)
}
EricBAndrews marked this conversation as resolved.
Show resolved Hide resolved
.foregroundStyle(.white)
.padding([.top, .trailing], 5)
.padding([.bottom, .leading], 15)
.contentShape(.rect)
.onTapGesture {
soundOn.wrappedValue = !soundOn.wrappedValue
}
}
}
}
}

extension View {
func withAnimationControls(animating: Binding<Bool>) -> some View {
modifier(AnimationControlLayer(animating: animating))
func withAnimationControls(animating: Binding<Bool>, soundOn: Binding<Bool>? = nil) -> some View {
modifier(AnimationControlLayer(animating: animating, soundOn: soundOn))
}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.