mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Fix playback of encrypted videos.
Encrypted videos from Element iOS were being stored with a `.Video` extension which was confusing AVFoundation.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
import Combine
|
import Combine
|
||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
class RoomTimelineController: RoomTimelineControllerProtocol {
|
class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||||
private let userId: String
|
private let userId: String
|
||||||
@@ -400,8 +401,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is not great. We could better estimate file extension from the mimetype.
|
let fileExtension = movieFileExtension(for: timelineItem.text)
|
||||||
let fileExtension = String(timelineItem.text.split(separator: ".").last ?? "mp4")
|
|
||||||
switch await mediaProvider.loadFileFromSource(source, fileExtension: fileExtension) {
|
switch await mediaProvider.loadFileFromSource(source, fileExtension: fileExtension) {
|
||||||
case .success(let fileURL):
|
case .success(let fileURL):
|
||||||
guard let index = timelineItems.firstIndex(where: { $0.id == timelineItem.id }),
|
guard let index = timelineItems.firstIndex(where: { $0.id == timelineItem.id }),
|
||||||
@@ -416,6 +416,26 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Temporary method that generates a file extension for a video file name
|
||||||
|
/// using `UTType.movie` and falls back to .mp4 if anything goes wrong.
|
||||||
|
///
|
||||||
|
/// Ideally Rust should be able to handle this for us, otherwise we should be
|
||||||
|
/// attempting to detect the file type from the data itself.
|
||||||
|
private func movieFileExtension(for text: String) -> String {
|
||||||
|
let fallbackExtension = "mp4"
|
||||||
|
|
||||||
|
// This is not great. We could better estimate file extension from the mimetype.
|
||||||
|
guard let fileExtensionComponent = text.split(separator: ".").last else { return fallbackExtension }
|
||||||
|
let fileExtension = String(fileExtensionComponent)
|
||||||
|
|
||||||
|
// We can't trust that the extension provided is an extension that AVFoundation will accept.
|
||||||
|
guard let fileType = UTType(filenameExtension: fileExtension),
|
||||||
|
fileType.isSubtype(of: .movie)
|
||||||
|
else { return fallbackExtension }
|
||||||
|
|
||||||
|
return fileExtension
|
||||||
|
}
|
||||||
|
|
||||||
private func loadFileForImageTimelineItem(_ timelineItem: ImageRoomTimelineItem) async {
|
private func loadFileForImageTimelineItem(_ timelineItem: ImageRoomTimelineItem) async {
|
||||||
if timelineItem.cachedFileURL != nil {
|
if timelineItem.cachedFileURL != nil {
|
||||||
// already cached
|
// already cached
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Video playback: Fix playback of encrypted video files.
|
||||||
Reference in New Issue
Block a user