Skip to content

Commit

Permalink
set userAgent to KSPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Jan 15, 2024
1 parent ef2becb commit b3c44d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
21 changes: 3 additions & 18 deletions Demo/SwiftUI/Shared/MovieModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class MEOptions: KSOptions {
#endif
override init() {
super.init()
formatContextOptions["reconnect_on_network_error"] = 1
audioLocale = Locale(identifier: "en-US")
}

Expand Down Expand Up @@ -293,28 +292,14 @@ extension KSVideoPlayerView {
}
#endif
options.referer = model.httpReferer
options.userAgent = model.httpUserAgent
if let httpUserAgent = model.httpUserAgent {
options.userAgent = httpUserAgent
}
let playmodel = model.getPlaymodel()
playmodel.playTime = Date()
if playmodel.duration > 0, playmodel.current > 0, playmodel.duration > playmodel.current + 120 {
options.startPlayTime = TimeInterval(playmodel.current)
}
// There is total different meaning for 'listen_timeout' option in rtmp
// set 'listen_timeout' = -1 for rtmp、rtsp
if url.scheme == "rtmp" || url.scheme == "rtsp" {
options.formatContextOptions["listen_timeout"] = -1
options.formatContextOptions["fflags"] = ["nobuffer"]
// tcp or udp
options.formatContextOptions["rtsp_transport"] = "tcp"
options.probesize = 4096
options.maxAnalyzeDuration = 2_000_000
options.codecLowDelay = true
options.preferredForwardBufferDuration = 1
options.maxBufferDuration = 3600
options.hardwareDecode = false
} else {
options.formatContextOptions["listen_timeout"] = 3
}
playmodel.save()
model.save()
self.init(url: url, options: options, title: model.name)
Expand Down
9 changes: 3 additions & 6 deletions Sources/KSPlayer/AVPlayer/KSOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,9 @@ open class KSOptions {
}
}

public var userAgent: String? {
public var userAgent: String = "KSPlayer" {
didSet {
if let userAgent {
formatContextOptions["user_agent"] = userAgent
} else {
formatContextOptions["user_agent"] = nil
}
formatContextOptions["user_agent"] = userAgent
}
}

Expand Down Expand Up @@ -110,6 +106,7 @@ open class KSOptions {
public internal(set) var decodeAudioTime = 0.0
public internal(set) var decodeVideoTime = 0.0
public init() {
formatContextOptions["user_agent"] = userAgent
// 参数的配置可以参考protocols.texi 和 http.c
// 这个一定要,不然有的流就会判断不准FieldOrder
formatContextOptions["scan_all_pmts"] = 1
Expand Down

0 comments on commit b3c44d7

Please sign in to comment.