- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 iOS 设备上播放受 Fairplay DRM 保护(通过 Azure 媒体服务加密)的 HLS 视频流。我使用了以下链接中描述的代码和过程:
https://icapps.com/blog/how-integrate-basic-hls-stream-fairplay
https://gist.github.com/fousa/5709fb7c84e5b53dbdae508c9cb4fadc
以下是我为此编写的代码。
import UIKit
import AVFoundation
class ViewController: UIViewController, AVAssetResourceLoaderDelegate {
@IBOutlet weak var videoView: UIView!
var player: AVPlayer!
override func viewDidLoad() {
super.viewDidLoad()
let streamURL = "someexampleurl.com/stream.m3u8"
if let url = URL(string: streamURL) {
//2. Create AVPlayer object
let asset = AVURLAsset(url: url)
let queue = DispatchQueue(label: "Some queue")
asset.resourceLoader.setDelegate(self, queue: queue)
let playerItem = AVPlayerItem(asset: asset)
player = AVPlayer(playerItem: playerItem)
//3. Create AVPlayerLayer object
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.videoView.bounds //bounds of the view in which AVPlayer should be displayed
playerLayer.videoGravity = .resizeAspect
//4. Add playerLayer to view's layer
self.videoView.layer.addSublayer(playerLayer)
//5. Play Video
player.play()
}
// Do any additional setup after loading the view.
}
func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool {
// We first check if a url is set in the manifest.
guard let url = loadingRequest.request.url else {
print("🔑", #function, "Unable to read the url/host data.")
loadingRequest.finishLoading(with: NSError(domain: "com.error", code: -1, userInfo:
nil))
return false
}
print("🔑", #function, url)
// When the url is correctly found we try to load the certificate date. Watch out! For this
// example the certificate resides inside the bundle. But it should be preferably fetched from
// the server.
guard
let certificateURL = Bundle.main.url(forResource: "certfps", withExtension: "cer"),
let certificateData = try? Data(contentsOf: certificateURL) else {
print("🔑", #function, "Unable to read the certificate data.")
loadingRequest.finishLoading(with: NSError(domain: "com.error", code: -2, userInfo: nil))
return false
}
// Request the Server Playback Context.
let contentId = "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
guard
let contentIdData = contentId.data(using: String.Encoding.utf8),
let spcData = try? loadingRequest.streamingContentKeyRequestData(forApp: certificateData, contentIdentifier: contentIdData, options: nil),
let dataRequest = loadingRequest.dataRequest else {
loadingRequest.finishLoading(with: NSError(domain: "com.error", code: -3, userInfo: nil))
print("🔑", #function, "Unable to read the SPC data.")
return false
}
// Request the Content Key Context from the Key Server Module.
let ckcURL = URL(string: "https://xxxxx.keydelivery.northeurope.media.azure.net/FairPlay/?kid=xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")!
var request = URLRequest(url: ckcURL)
request.httpMethod = "POST"
let assetIDString = "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
let postString = "spc=\(spcData.base64EncodedString())&assetId=\(assetIDString)"
request.setValue(String(postString.count), forHTTPHeaderField: "Content-Length")
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpBody = postString.data(using: .ascii, allowLossyConversion: true)
let session = URLSession(configuration: URLSessionConfiguration.default)
let task = session.dataTask(with: request) { data, response, error in
if let data = data {
// The CKC is correctly returned and is now send to the `AVPlayer` instance so we
// can continue to play the stream.
if var responseString = String(data: data, encoding: .utf8) {
responseString = responseString.replacingOccurrences(of: "<ckc>", with: "").replacingOccurrences(of: "</ckc>", with: "")
var ckcData = Data(base64Encoded: responseString)!
dataRequest.respond(with: ckcData)
loadingRequest.finishLoading()
} else {
// print("Error encountered while fetching FairPlay license for URL: \(self.drmUrl), \(error?.localizedDescription ?? "Unknown error")")
}
task.resume()
return true
}
}
上面的一切都有效,但在我得到的 CKC 响应中
{
"Error": {
"Message": "Failed content key policy evaluation.",
"Code": "AuthorizationPolicyEvaluationFailure"
}
}
有人可以告诉我我在这里缺少什么吗,这是我第一次尝试这个所以我可能会犯一个非常明显的错误,所以请耐心等待。
任何有关这方面的帮助都会非常好(我已经为此苦苦思索好几天了。)
谢谢。
最佳答案
可能有助于排除故障的一件事是启用许可证传送日志记录。您可以在 Azure 门户中执行此操作,方法是转到您的媒体服务帐户,在“监视”部分中转到“诊断设置”。单击“添加诊断设置”。为设置命名,然后(至少在开始时)告诉它存档到存储帐户。记录“KeyDeliveryRequests”。保存后重现该问题。然后转到您的存储帐户并查找日志结果。存储容器“insights-logs-keydeliveryrequests”将包含日志。
关于ios - Azure 媒体服务 Fairplay DRM AVPlayer 快速实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60186085/
我有一个 AVPlayer当我到达持续时间结束时,我想回到开始,但我不想重新启动AVPlayer . //Do something when video ended NotificationCente
我正在使用 AVPlayer 从服务器流式传输音频,我现在想做的是显示一个显示缓冲进度的自定义 UISlider。 有人想出这个吗?请给我解决方案。现在播放器一次加载整个持续时间并在 UISlider
我知道 AVPlayerItem(AVPlayer 的子类)能够订阅 AVPlayerItemDidPlayToEndTimeNotification AVPlayer 没有这样的功能,我需要使用 A
总结: 如果您只使用 AVPlayer 在您的应用程序中播放流音频,那么锁屏更新将工作得很好(许多流 - 一个接一个)。但是,如果您使用 AVPlayer 播放流式音频,然后播放本地视频文件(即使在使
我正在尝试创建像 Vine 这样的应用程序。我有一个 Collection View ,其中每个项目都包含一个带有 AVPlayerLayer 和 AVPlayer 实例的 View ,并且相应的 a
我创建了一个简单的 AVPlayer。 (如果我没有正确创建它,请帮我修复它...😀)我想用 swift ui 在我的 VStack 中显示它,但我有点卡住了... 如果库里至少有AVPlayer
我已将观察者添加到 AVPlayer,但它不会在 avplayer 状态准备好播放时调用该函数。该函数在视频开始播放时调用两次,但 AVPlayer 的持续时间参数都返回“nan”,我需要在 AVPl
我有 2 个 View Controller ,第一个包含一个视频信息列表表,然后从列表中选择一个项目,通过导航打开详细 View Controller 。我在这个细节 Controller 上使用了
关于这个主题的所有线程都非常老(5+ 哟),我似乎无法形成一个清晰的现代方法,所以希望这可以在 2020 年(Swift 5,Xcode 11)进行总结。 如果您要使用 为 iPhone 构建一个 A
我有一个 AVPlayer 可以从网络流式传输 mp3 文件。我已经激活了一个 AVAudioSession 以便在应用程序退出/屏幕关闭时播放音频。音乐播放完美,但手机顶部状态菜单中出现的“播放”三
我正在使用 Apple 的文档演示。这是演示链接: AVPlayerDemo 我的应用程序在执行以下步骤后崩溃了: 1) 播放歌曲 2) 从搜索栏快进。 3)点击下一步,4) 从搜索栏快进。 这是我的
因此看来,实际起作用的唯一值是0.0、0.5、1.0和2.0 ... 我尝试将其设置为0.25,因为我希望它以自然速度的1/4播放,但它却以自然速度的1/2播放。有人可以确认吗? 最佳答案 已确认。实
我有一个应用程序,它通过 AVMutableComposition 将本地文件加载到 avPlayer 中,它可能有多达 6 个音频和视频轨道作为合成的一部分。 我有一个 UISlider,用于调整播
在我的 IOS 应用程序中使用 AVPlayer 显示短视频的屏幕。我成功离开并重新进入此屏幕几次,但在七次或更多次后,我得到空白屏幕并且 AVPlayerLayer 的 IsReadyForDisp
我正在开发一个应用程序,其中包括使用每帧动画播放视频的功能。 您可以看到 example这样的功能。 我已经尝试添加 CAKeyFrameAnimation到 AVSynchronizedLayer
如何在 osx 自动播放中制作 avplayer? 我试过这个: NSURL *videoURL = [[NSBundle mainBundle] URLForResource:@"video nam
iOS AVPlayer 的默认最大和最小缓冲区大小是多少?如何增加 mp3 流媒体的大小?谢谢你 最佳答案 如果您的 缓冲区大小 意味着播放缓冲区,那么我相信这个大小没有记录。 此行为由 AVFou
我正在使用多个 AVPlayer 在我的屏幕上显示内容,并且它们都同时播放视频。 问题是有时 avplayer 正在播放,但 avplayerlayer 没有显示任何内容 - 你得到的只是一个空白屏幕
我正在使用 AVPlayer 在我的应用程序中播放视频,现在我想让视频在后台模式下播放。 这是我放入 - (BOOL)application:(UIApplication *)application
我在 iOS 6.1 中使用 AVPlayer 对象。我目前正在连接到 Icecast 服务器以传输现场音乐源。但是,当流由于任何原因(例如重新启动或信号更改)而中断时,AVPlayer 会停止播放。
我是一名优秀的程序员,十分优秀!