Add custom header field in request of AVPlayer
You'll need to request the data yourself via a generic HTTP connection mechanism such as NSURLConnection
. If the NSHTTPURLResponse
's headers pass your test, then you should save it into the NSCachesDirectory
and pass off the URL to this resource to the AVPlayer
like so:
NSData *data = //your downloaded data.
NSString *filePath = //generate random path under NSCachesDirectory
[data writeToFile:filePath atomically:YES];
AVPlayer *player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:filePath]];
//...
Is it possible to configure custom headers for AVPlayerItem URLRequest?
when you are creating AVURLAsset
you can add an option AVURLAssetHTTPHeaderFieldsKey
and provide your HTTP headers. The code should look similar to:
let asset = AVURLAsset(url: url, options:["AVURLAssetHTTPHeaderFieldsKey": yourHttpHeaders])
let item = AVPlayerItem(asset: asset)
let player = AVPlayer(playerItem: item)
Related Topics
How to Use Autolayout to Set Constraints on My Uiscrollview
In iOS 12, When Does the Uicollectionview Layout Cells, Use Autolayout in Nib
Should I Declare Variables in Interface or Using Property in Objective-C Arc
How to Display Activity Indicator in Center of Uialertcontroller
Cannot Put a Google Maps Gmsmapview in a Subview of Main Main View
Nsurlconnection Get Request Returns -1005, "The Network Connection Was Lost"
How to Handle Image Scale on All the Available iPhone Resolutions
iOS 11 Customise Search Bar in Navigation Bar
Get MAC Address of Bluetooth Low Energy Peripheral in iOS
Dealing with iPad Mini Screen Size
Formatting a Uitextfield for Credit Card Input Like (Xxxx Xxxx Xxxx Xxxx)
Force Landscape Mode in One Viewcontroller Using Swift
Add Custom Header Field in Request of Avplayer
Using Nsuserdefaults with Xcode 8 and iOS 10
How to Programmatically Enable Guided Access (Kiosk Mode) on an Iphone