Skip to content

Commit

Permalink
APIを変更
Browse files Browse the repository at this point in the history
  • Loading branch information
zztkm committed Oct 2, 2024
1 parent d1afe08 commit 7c92762
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Sora/SwiftUIVideoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ public struct SwiftUIVideoView<Background>: View where Background: View {
private var stream: MediaStream?
private var background: Background

// TODO(zztkm): わかりやすいコメントを書く
// 親 View で定義された stopVideo 変数と接続するための変数
@Binding private var stopVideo: Bool?

@ObservedObject private var controller: VideoController

/**
ビューを初期化します。

- parameter stream: 描画される映像ストリーム。 nil の場合は何も描画されません
*/
public init(_ stream: MediaStream?) where Background == EmptyView {
self.init(stream, background: EmptyView())
public init(_ stream: MediaStream?, stopVideo: Binding<Bool>? = nil) where Background == EmptyView {
self.init(stream, background: EmptyView(), stopVideo: stopVideo)
}

/**
Expand All @@ -26,9 +30,10 @@ public struct SwiftUIVideoView<Background>: View where Background: View {
- parameter stream: 描画される映像ストリーム nil の場合は何も描画されません
- paramater background: 映像のクリア時に表示する背景ビュー
*/
public init(_ stream: MediaStream?, background: Background) {
public init(_ stream: MediaStream?, background: Background, stopVideo: Binding<Bool>?) {
self.stream = stream
self.background = background
self._stopVideo = stopVideo
controller = VideoController(stream: stream)
}

Expand All @@ -40,6 +45,9 @@ public struct SwiftUIVideoView<Background>: View where Background: View {
RepresentedVideoView(controller)
.opacity(controller.isCleared ? 0 : 1)
}
.onChange(of: stopVideo, initial: true) { newValue in
videoStop(newValue)
}
}

/**
Expand Down Expand Up @@ -81,7 +89,7 @@ public struct SwiftUIVideoView<Background>: View where Background: View {
映像の描画を停止します。
TODO(zztkm): State で更新できるか確認する
*/
public func videoStop(_ flag: Bool) -> SwiftUIVideoView<Background> {
private func videoStop(_ flag: Bool) -> SwiftUIVideoView<Background> {
print("kensaku: videoStop(\(flag))")
if flag {
controller.videoView.stop()
Expand Down

0 comments on commit 7c92762

Please sign in to comment.