Skip to content

Commit c68828c

Browse files
committed
Update Video8.swift
1 parent 7fc70f4 commit c68828c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

swiftui-loop-videoplayer-example/views/video/Video8.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ struct Video8: VideoTpl {
4040
.onPlayerTimeChange(perform: onPlayerTimeChange)
4141
.onPlayerEventChange(perform: onPlayerEventChange)
4242
}
43+
.onChange(of: viewModel.duration){ value in
44+
if value > 0 {
45+
playbackCommand = .play
46+
}
47+
}
4348
.ignoresSafeArea()
4449
.overlay(timeScaleTpl, alignment: .bottom)
4550
.toolbar { toolbarTpl }
4651
.onAppear { handleVideoSelectionChange(selectedVideoURL) }
52+
4753
}
4854

4955
private var timeScaleTpl : some View{
@@ -73,6 +79,7 @@ struct Video8: VideoTpl {
7379
}
7480

7581
private func handleVideoSelectionChange(_ newURL: String) {
82+
playbackCommand = .pause
7683
viewModel.getDuration(from: newURL)
7784
settings = getSettings(for: newURL)
7885
}
@@ -101,6 +108,7 @@ fileprivate func getSettings(for name: String) -> VideoSettings{
101108
SourceName(name)
102109
Gravity(.resizeAspectFill)
103110
TimePublishing()
111+
NotAutoPlay()
104112
Mute()
105113
}
106114
}

0 commit comments

Comments
 (0)