I am developing a music app from a third party API provider(www.mndigital.com). The API provider gives a 30 second demo for each song. The location of the demo app are given in this format
"SampleLocations": [
{
"Location": "rtmp://mn-ecn-prd-rtmp.mndigital.com",
"Resource": "mp3:/spl/382/071/327/spl_024?48d882e51ff49ca3806e4b63d90b926556349db16cecf61947a8eb9a44f9bee3bf7d",
"Type": "s_mp3"
},
{
"Location": "rtmp://mn-ecn-prd-rtmp.mndigital.com",
"Resource": "mp4:/spl/382/071/327/spl_029.mp4?48d882e51ff49ca3806e4b63d90b926556349db16cecf61947a8eb9a44f9bee3bf7d",
"Type": "s_mp4"
}
],
also the API provider says that the samples must be streamed live
from server and should not be saved locally
, in the terms and conditions.
After a few hours of searching i found that this format is for playing audio in a flash player. But in IOS flash player is not supported.
even for the AVPlayer
to work we need only one url in the updated swift syntax
do {
let url = "http://yourdomain.com/file.mp3"
let fileURL = NSURL(string:url)
let soundData = NSData(contentsOfURL:fileURL!)
self.audioPlayer = try AVAudioPlayer(data: soundData!)
audioPlayer.prepareToPlay()
audioPlayer.volume = 1.0
audioPlayer.delegate = self
audioPlayer.play()
} catch {
print("Error getting the audio file")
}
So i don't know how to stream this kind of url in swift. Could anyone suggest a solution.
I am using swift 2.0 xcode 7.1.1 . My deployment target is IOS 8.0 and above
After a long search i found that rtmp files cannot be played in apple devices as apple does not support flash payers. There is no way to play any data that provided by the URLs of these format.