I would like to play a video file which I fetched from a server. I may add that I am using the following plugin Player (which seems to act pretty much like AVPlayer). Just like in the AVPlayer one can set a url like this self.player.url = URL(string: video!)
(video being the URL) and the video file is downloaded and can then be played. However, since I would like to cache the videos, I want the actual file to be played. How would I play the file? Would I need to convert it to NSData or get its file path as shown in this question (he calls it "hacky way to get filepath")? The library says one can do it like this:
let videoUrl: NSURL = // file or http url
self.player.setUrl(videoUrl)
But I can't see a way I can put a file in there since it isn't URL...
For the cache I use another library called Carlos. As suggested I make a simple request and see if it succeeds or not. If it does succeed, I want the file to be used in the player:
let request = HomeController().cache.get(URL(string: video!)!)
//success means a file is downloaded (in this case "videoFile") and a value for a key is set on the memory cache (the key is going to be the URL (on server))
request.onSuccess { videoFile in
//I can print the file
print("The file: \(videoFile)")
//WITHOUT CACHE: just enter URL to video (on server)
//self.player.url = URL(string: video!)
//how to do it WITH CACHE?
self.player.
self.player.playbackLoops = true
}
.onFailure { error in
print("An error occurred :( \(error)")
}
I would also be open to solutions using the AVPlayer instead of the library.
EDIT: Output:
Since the file is 1.2 MB big, I will provide the star and the end...
How it starts:
The file <0000001c 66747970 6d703432 00000001 6d703431 6d703432 69736f6d 00000008 77696465 001442b8 6d646174 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00cc0007 00f85500 4ca0f24a ab56b172 8a912aaa aaa80044 5d965965 96594420 7000fc99 3ef8866a ec633459 a614f7e0 e355a9be ff8f7d67 15d79712 fff4f123 5777c6ba 4e6f111c 059e33c8 7149cda6 ...
How it ends
... 73000023 32000009 71000013 ea000009 9f000011 87000005 4e000016 1a000007 c1000014 e1000007 53000013 b4000003 c4000015 0b000005 0e000012 17000008 60000013 9800000a 0a00001a 0500000a cd000015 93000008 5c000014 47000009 b7000016 0c00000a 6b000016 2b00000a 43000016 0e000008 4100001b bd000007 dd000010 ee000006 a8000014 20000007 41000016 e6000007 27000013 54000005 84000015 90000007 9700001a 41000008 f1000017 f2000005 df000011 fb000008 0d000011 69000006 51000015 2f000005 c9000015 2e000006 9b000016 24000005 42000014 e8000005 fb000015 bb000006 58000019 0b000005 f5000011 ae000005 c700000f e7000005 75000010 40000005 0300000e e9000005 cc00000e 2e000005 e5000012 67000004 c7000019 17000005 bc00001a 4e000008 ce00001c 6b000009 0e00001c 23000006 cc000017 ff000005 c5000019 32000007 22000017 d7000006 ce000019 2e000006 9600001a 20000005 fb000011 61000005 fb000012 0b000005 df000012 dc000006 b2000010 35000005 4b000014 5a000005 26000011 c0000004 99000014 16000004 b400001b d1000006 f8000011 25000006 4a00000e bd000005 c6000011 85000005 b2000013 24000004 6900000f 6a000005 f300000e 57000005 bc000012 6d000055 f000000e 2b000003 d300000e a7000003 8700000f 0d000004 26000015 00000000 5c737463 6f000000 00000000 13000030 a9000152 ea000268 8500035b f4000472 9a00057c 2800068e 4300079f ad0008b1 3c0009a8 41000aba fe000bc9 6d000cee ab000dbe 1b000ec8 7c000fa9 eb001089 87001138 1a0012e7 31>