Skip to content

Commit

Permalink
[#50]fix: fix demo's play media error (#52)
Browse files Browse the repository at this point in the history
* [#50]fix: fix demo's play media error
  • Loading branch information
wzxha authored Apr 19, 2024
1 parent dbf7cf2 commit 055b37a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Demo/Demo/Demo-iOS/FileListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,22 @@ class FileListViewController: UIViewController {

/// 播放音频
@MainActor
private func playMedia(_ url: URL) {
private func playMedia(_ url: URL, mimeType: String?) {
let headers = [
"Authorization": "Bearer \(client.accessToken ?? "")"
]
let asset = AVURLAsset(url: url, options: [
"AVURLAssetHTTPHeaderFieldsKey": headers
])
let asset: AVURLAsset
if #available(iOS 17.0, *), let mimeType {
asset = AVURLAsset(url: url, options: [
"AVURLAssetHTTPHeaderFieldsKey": headers,
AVURLAssetOverrideMIMETypeKey: mimeType
])
} else {
asset = AVURLAsset(url: url, options: [
"AVURLAssetHTTPHeaderFieldsKey": headers
])
}

let playerItem = AVPlayerItem(asset: asset)
let player = AVPlayer(playerItem: playerItem)
let playerViewController = AVPlayerViewController()
Expand Down Expand Up @@ -139,7 +148,7 @@ extension FileListViewController: UICollectionViewDelegate {
.last

if let playURL {
playMedia(playURL)
playMedia(playURL, mimeType: file.mime_type)
}
} catch {
print(error)
Expand All @@ -156,7 +165,7 @@ extension FileListViewController: UICollectionViewDelegate {
.init(
drive_id: file.drive_id,
file_id: file.file_id))).url
playMedia(playURL)
playMedia(playURL, mimeType: file.mime_type)
} catch {
print(error)
}
Expand Down Expand Up @@ -203,7 +212,7 @@ extension FileListViewController: FileCellDelegate {
return
}
if item.file.category == .video {
playMedia(url)
playMedia(url, mimeType: item.file.mime_type)
} else {
let viewController = UIDocumentInteractionController(url: url)
viewController.delegate = self
Expand Down
1 change: 1 addition & 0 deletions Sources/AliyunpanSDK/Model/AliyunpanFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public struct AliyunpanFile: Codable {
public let content_hash: String?
public var category: FileCategory?
public let type: FileType?
public let mime_type: String?
/// 缩略图
public let thumbnail: URL?
/// 图片预览图地址、小于 5MB 文件的下载地址。超过5MB 请使用 /getDownloadUrl
Expand Down
1 change: 1 addition & 0 deletions Tests/AliyunpanSDKTests/DownloaderTaskTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let file = AliyunpanFile(
file_extension: nil,
content_hash: nil,
type: .file,
mime_type: nil,
thumbnail: nil,
url: nil,
created_at: nil,
Expand Down
1 change: 1 addition & 0 deletions Tests/AliyunpanSDKTests/DownloaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class DownloaderTests: XCTestCase {
file_extension: nil,
content_hash: nil,
type: .file,
mime_type: nil,
thumbnail: nil,
url: nil,
created_at: nil,
Expand Down

0 comments on commit 055b37a

Please sign in to comment.