Open hirenspaceo opened 7 years ago
How are you making local file url? Use this code to make the url:
let mp3FileName = "david.mp3"
var fileManager = NSFileManager.defaultManager()
var wayToFile = fileManager .URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask)
var passMusicFileURL: NSURL?
if let documentPath: NSURL = wayToFile.first as? NSURL {
let musicFile = documentPath.URLByAppendingPathComponent(mp3FileName )
println(musicFile)
passMusicFileURL = musicFile
let filePathURL:URL! = URL.init(fileURLWithPath: filePth, isDirectory: false)
if (filePathURL != nil){
let item = JukeboxItem.init(URL: filePathURL, localTitle: "Song Title")
jukeboxPlaylist.add(item)
}
}
Thanks a lot @RajChanchal.
This code solve my problem. Thank you very much
Getting fatal error on xcode 8.2 while playing it from document directory any suggestion
let mp3FileName = "introduction.mp3"
let fileManager = FileManager.default
let wayToFile = fileManager .urls(for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchPathDomainMask.userDomainMask)
var passMusicFileURL: NSURL?
if let documentPath: NSURL = wayToFile.first as NSURL? {
let musicFile = documentPath.appendingPathComponent(mp3FileName )
print(musicFile!)
passMusicFileURL = musicFile! as NSURL
let filePathURL:URL! = URL.init(fileURLWithPath: path, isDirectory: false)
if (filePathURL != nil){
let item = JukeboxItem.init(URL: filePathURL, localTitle: "Song Title")
//jukeboxPlaylist.add(item)
jukebox.append(item: item, loadingAssets: true)
// jukebox.play()
}
@abdulKarim002 kindly check if musicFile
is not nil
musicfile i am getting like the file:///Users/im038/Library/Developer/CoreSimulator/Devices/5E2B9097-576A-4636-B397-0283EC29D72C/data/Containers/Data/Application/7C9BE57E-BF20-4485-B4A0-8165FCB3A963/Documents/01-PURUSHARTHA.mp3
but my application is crashing at this point
let mp3FileName = indexData["mp3Url"] as? String
let fileManager = FileManager.default
let wayToFile = fileManager.urls(for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchPathDomainMask.userDomainMask)
var passMusicFileURL: NSURL?
if let documentPath: NSURL = wayToFile.first as NSURL? {
let musicFile = documentPath.appendingPathComponent(mp3FileName!)
print(musicFile!)
passMusicFileURL = musicFile as NSURL?
let filePathURL:URL! = URL.init(fileURLWithPath: "\(String(describing: passMusicFileURL!))", isDirectory: false)
if (filePathURL != nil){
let item = JukeboxItem.init(URL: filePathURL!, localTitle: "Song Title")
jukebox.append(item: item, loadingAssets: true) --- fatel error
// jukebox.play()
}
}
Hello,
I want to play song from document directory folder. Because in my application i give both support online play and offline play. i set document directory path as URL but it not load assets,