gpt4 book ai didi

ios - 如何在 iOS 应用程序中播放播客文件

转载 作者:可可西里 更新时间:2023-11-01 02:10:50 27 4
gpt4 key购买 nike

我正在开发包含广播和播客的应用程序。我可以在哪里播放实时流媒体广播。此外,我正在从 iTunes 获取播客列表,但没有找到歌曲的流媒体链接作为响应。响应给出音频文件集合的链接。那么如何获取声音文件实际路径的链接呢?

https://itunes.apple.com/search?term=song&country=IN&media=podcast&entity=podcast

   import AFNetworking

class PodcastApi {

fileprivate let baseUrl = URL(string: "https://itunes.apple.com/")
/// Shared singletone object of WSApi
static let shared : PodcastApi = {
let instance = PodcastApi()
return instance
}()


private func showNetworkActivity(){
// Turn on network indicator in status bar
UIApplication.shared.isNetworkActivityIndicatorVisible = true
}

private func hideNetworkActivity(){
// Turn off network indicator in status bar
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}

private func getPath(term:String)->String{
return "search?term=\(term)&country=IN&media=podcast&entity=podcast"
}

func getPodcasts(term:String,completionHandler:@escaping (_ status:Bool, _ responseObject:Any)->()){

if !ReachabilityManager.shared.isReachable {
let error = WSError()
error.errorTitle = "Network error"
error.errorDescription = "Unable to connect, please check your internet connectivity."
completionHandler(false,error)
return
}

self.showNetworkActivity()
let sessionManager = AFHTTPSessionManager(baseURL: baseUrl, sessionConfiguration: URLSessionConfiguration.default)
sessionManager.requestSerializer = AFJSONRequestSerializer()
sessionManager.responseSerializer = AFJSONResponseSerializer()
let urlPath = getPath(term: term)

sessionManager.get(urlPath, parameters: nil, progress: { progress in

}, success: { task, responseObject in

self.hideNetworkActivity()
var podcasts = [Podcast]()
if let disc = responseObject as? [String:Any]{
podcasts.append(contentsOf: Podcast.GetPodcasts(disc: disc))
}
completionHandler(true,podcasts)

}, failure: { operation, err in
self.hideNetworkActivity()
let error = WSError(error: err as NSError)
completionHandler(false,error)

})

}

}

Response is

{
"wrapperType": "track",
"kind": "podcast",
"collectionId": 415636728,
"trackId": 415636728,
"artistName": "Kurt Nichols",
"collectionName": "New Song Fellowship",
"trackName": "New Song Fellowship",
"collectionCensoredName": "New Song Fellowship",
"trackCensoredName": "New Song Fellowship",
"collectionViewUrl": "https://itunes.apple.com/in/podcast/new-song-fellowship/id415636728?mt=2&uo=4",
"feedUrl": "http://lily.nowsprouting.com/newsongfellowship/podcast.php?pageID=10",
"trackViewUrl": "https://itunes.apple.com/in/podcast/new-song-fellowship/id415636728?mt=2&uo=4",
"artworkUrl30": "http://is4.mzstatic.com/image/thumb/Music62/v4/34/b0/16/34b016de-a98f-0bc2-38ca-45ed2f22fe65/source/30x30bb.jpg",
"artworkUrl60": "http://is4.mzstatic.com/image/thumb/Music62/v4/34/b0/16/34b016de-a98f-0bc2-38ca-45ed2f22fe65/source/60x60bb.jpg",
"artworkUrl100": "http://is4.mzstatic.com/image/thumb/Music62/v4/34/b0/16/34b016de-a98f-0bc2-38ca-45ed2f22fe65/source/100x100bb.jpg",
"collectionPrice": 0,
"trackPrice": 0,
"trackRentalPrice": 0,
"collectionHdPrice": 0,
"trackHdPrice": 0,
"trackHdRentalPrice": 0,
"releaseDate": "2015-12-04T18:00:00Z",
"collectionExplicitness": "cleaned",
"trackExplicitness": "cleaned",
"trackCount": 30,
"country": "IND",
"currency": "INR",
"primaryGenreName": "Christianity",
"contentAdvisoryRating": "Clean",
"artworkUrl600": "http://is4.mzstatic.com/image/thumb/Music62/v4/34/b0/16/34b016de-a98f-0bc2-38ca-45ed2f22fe65/source/600x600bb.jpg",
"genreIds": [
"1439",
"26",
"1314"
],
"genres": [
"Christianity",
"Podcasts",
"Religion & Spirituality"
]
}

最佳答案

据我所知 iTunes 本身不存储播客。相反,播客提供(主要是 rss-feeds)包含 XML ,其中包含指向播客剧集文件的链接。

提要是您响应中“feedUrl”的值。

"feedUrl": "http://lily.nowsprouting.com/newsongfellowship/podcast.php?pageID=10"

这些提要看起来类似于这种形式:

  • 带有 xml 版本、unicode 和 itunes dtd 的“ header ”

  • channel -

  • 付...

    然后是提要中可用的每个播客的(字面意思是它的名称)项目,形式为:

this is from the podcast you mentioned, url to mp3 highlighted

如果你想解析它,你想读入 XMLParser ;-) https://developer.apple.com/documentation/foundation/xmlparser

关于ios - 如何在 iOS 应用程序中播放播客文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40996963/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com