Commit 7913f764 authored by shigemi miura's avatar shigemi miura

Webブラウザを開いて動画を再生

parent aad76f2a
...@@ -4,12 +4,10 @@ ...@@ -4,12 +4,10 @@
// //
// Created by Mamoru Sugita on 2023/11/08. // Created by Mamoru Sugita on 2023/11/08.
// //
import SwiftUI import SwiftUI
import AVKit import AVKit
struct MyChatContentView: View { struct MyChatContentView: View {
@State private var isVideoPlayerPresented = false
var message : ChatMessage var message : ChatMessage
var onMediaLoaded: (() -> Void)? = nil var onMediaLoaded: (() -> Void)? = nil
...@@ -22,9 +20,12 @@ struct MyChatContentView: View { ...@@ -22,9 +20,12 @@ struct MyChatContentView: View {
if msg.contains(".jpg") || msg.contains(".png") { if msg.contains(".jpg") || msg.contains(".png") {
ChatUrlImageView(imageUrl: msg, onLoad: onMediaLoaded) ChatUrlImageView(imageUrl: msg, onLoad: onMediaLoaded)
.onTapGesture { .onTapGesture {
if let videoUrl = message.videoUrl, var urlString: String = HttpRequestType.RawImage.rawValue
let url = URL(string: videoUrl) { urlString = urlString.replacingOccurrences(of: "XXXXX", with: String(message.shipId))
isVideoPlayerPresented = true urlString = urlString.replacingOccurrences(of: "YYYYY", with: String(message.messageId))
if let url = URL(string: urlString) {
UIApplication.shared.open(url)
} }
} }
} else { } else {
...@@ -73,12 +74,6 @@ struct MyChatContentView: View { ...@@ -73,12 +74,6 @@ struct MyChatContentView: View {
} }
.padding(.trailing, 20) .padding(.trailing, 20)
} }
.fullScreenCover(isPresented: $isVideoPlayerPresented) {
if let videoUrl = message.videoUrl,
let url = URL(string: videoUrl) {
VideoPlayerView(videoURL: url)
}
}
} }
func viewerCnt() -> (Int, Int) { func viewerCnt() -> (Int, Int) {
...@@ -95,16 +90,6 @@ struct MyChatContentView: View { ...@@ -95,16 +90,6 @@ struct MyChatContentView: View {
} }
} }
struct VideoPlayerView: View {
let videoURL: URL
var body: some View {
VideoPlayer(player: AVPlayer(url: videoURL))
.navigationTitle("動画再生")
.navigationBarTitleDisplayMode(.inline)
}
}
#Preview { #Preview {
MyChatContentView(message: ChatMessage( MyChatContentView(message: ChatMessage(
shipId: 10000003, shipId: 10000003,
......
...@@ -8,7 +8,6 @@ import SwiftUI ...@@ -8,7 +8,6 @@ import SwiftUI
import AVKit import AVKit
struct OtherChatContentView: View { struct OtherChatContentView: View {
@State private var isVideoPlayerPresented = false
var message : ChatMessage var message : ChatMessage
var onMediaLoaded: (() -> Void)? = nil var onMediaLoaded: (() -> Void)? = nil
...@@ -26,10 +25,12 @@ struct OtherChatContentView: View { ...@@ -26,10 +25,12 @@ struct OtherChatContentView: View {
if msg.contains(".jpg") || msg.contains(".png") { if msg.contains(".jpg") || msg.contains(".png") {
ChatUrlImageView(imageUrl: msg, onLoad: onMediaLoaded) ChatUrlImageView(imageUrl: msg, onLoad: onMediaLoaded)
.onTapGesture { .onTapGesture {
if message.type == 3, var urlString: String = HttpRequestType.RawImage.rawValue
let videoUrl = message.videoUrl, urlString = urlString.replacingOccurrences(of: "XXXXX", with: String(message.shipId))
let url = URL(string: videoUrl) { urlString = urlString.replacingOccurrences(of: "YYYYY", with: String(message.messageId))
isVideoPlayerPresented = true
if let url = URL(string: urlString) {
UIApplication.shared.open(url)
} }
} }
} else { } else {
...@@ -60,12 +61,6 @@ struct OtherChatContentView: View { ...@@ -60,12 +61,6 @@ struct OtherChatContentView: View {
.padding(.leading, 20) .padding(.leading, 20)
Spacer() Spacer()
} }
.fullScreenCover(isPresented: $isVideoPlayerPresented) {
if let videoUrl = message.videoUrl,
let url = URL(string: videoUrl) {
VideoPlayerView(videoURL: url)
}
}
} }
} }
......
...@@ -28,7 +28,6 @@ struct ChatMessage: Codable { ...@@ -28,7 +28,6 @@ struct ChatMessage: Codable {
var fromId: String? //ユーザーID var fromId: String? //ユーザーID
var mode: Int // 0:通常 , 1:Warning中 var mode: Int // 0:通常 , 1:Warning中
var message: String? //テキスト時:テキスト , 画像時:サムネイルのUri var message: String? //テキスト時:テキスト , 画像時:サムネイルのUri
var videoUrl: String? //TODO: - テスト
var stampId: Int //スタンプ番号 0:Fire~ var stampId: Int //スタンプ番号 0:Fire~
var Latitude: Double? //TODO: - テスト var Latitude: Double? //TODO: - テスト
var Longitude: Double? //TODO: - テスト var Longitude: Double? //TODO: - テスト
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment