mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-01 20:56:55 +00:00
9e8084874f
* ios: block members (WIP) * CIBlocked, blocking api * show item as blocked * show blocked and merge multiple deleted items * update block icons * split sent and received deleted to two categories * merge chat feature items, refactor CIMergedRange * merge feature items, two profile images and names on merged items * ensure range is withing chat items range * merge group events * fix/refactor * make group member changes observable * exclude some group events from merging * fix states not updating and other fixes * load list of members when tapping profile * refactor * fix incorrect merging of sent/received marked deleted * fix incorrect expand/hide on single moderated items without content * load members list when opening member via item * comments * fix member counting in case of name collision
61 lines
1.8 KiB
Swift
61 lines
1.8 KiB
Swift
//
|
|
// Created by Avently on 30.03.2023.
|
|
// Copyright (c) 2023 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
import AVKit
|
|
|
|
struct VideoPlayerView: UIViewRepresentable {
|
|
|
|
static var players: [String: AVPlayer] = [:]
|
|
static func getOrCreatePlayer(_ url: URL, _ gallery: Bool) -> AVPlayer {
|
|
if let player = players[url.absoluteString + gallery.description] {
|
|
return player
|
|
} else {
|
|
let player = AVPlayer(url: url)
|
|
players[url.absoluteString + gallery.description] = player
|
|
return player
|
|
}
|
|
}
|
|
|
|
typealias UIViewType = UIView
|
|
let player: AVPlayer
|
|
let url: URL
|
|
let showControls: Bool
|
|
|
|
func makeUIView(context: UIViewRepresentableContext<VideoPlayerView>) -> UIView {
|
|
let controller = AVPlayerViewController()
|
|
controller.showsPlaybackControls = showControls
|
|
if #available(iOS 16.0, *) {
|
|
controller.speeds = []
|
|
}
|
|
controller.player = player
|
|
context.coordinator.controller = controller
|
|
context.coordinator.timeObserver = NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: .main) { _ in
|
|
player.seek(to: CMTime.zero)
|
|
player.play()
|
|
}
|
|
return controller.view
|
|
}
|
|
|
|
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<VideoPlayerView>) {
|
|
}
|
|
|
|
func makeCoordinator() -> VideoPlayerView.Coordinator {
|
|
Coordinator()
|
|
}
|
|
|
|
class Coordinator: NSObject {
|
|
var controller: AVPlayerViewController?
|
|
var timeObserver: Any? = nil
|
|
|
|
deinit {
|
|
if let timeObserver = timeObserver {
|
|
NotificationCenter.default.removeObserver(timeObserver)
|
|
}
|
|
}
|
|
}
|
|
}
|