2
我正在開發包含廣播和播客的應用程序。在哪裏我可以播放直播流媒體。此外,我正在從iTunes獲取播客列表,但沒有找到響應歌曲的流媒體鏈接。響應給出了收集音頻文件的鏈接。那麼如何獲得鏈接到聲音文件的實際路徑?如何在iOS應用程序中播放播客文件
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"
]
}