iOS APP/SWIFT #4 (4–2) iOS SDK practices : AVplayer, liveView, SFSafariView
— Using AVPlayer to play music
import AVFoundation
import AVFoundation
let url = URL(string: "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview126/v4/5e/ba/92/5eba9224-4039-bfa2-7d5e-b5ac4a6dafbf/mzaf_5603415777182293762.plus.aac.p.m4a")
let player = AVPlayer(url: url!)
player.play()
Change the preview music of example
The fist is open the website and find a song
https://tools.applemediaservices.com
2nd Step is select a song and then copy the “Content Link”
“1444320940” is Album ID, “1444321282” is Song ID
3rd step : Open below path and change the ID to “1444321282”
https://itunes.apple.com/lookup?id=1444321282
Finally copy this URL to replace the path/file of the code
let url = URL (string: "https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/AudioPreview118/v4/69/0e/98/690e98db-440d-cb0c-2bff-91b00a05bdda/mzaf_1674062311671795807.plus.aac.p.m4a")
— Using AVPlayer and Playground Page.current.liveView to play and see the video file from websites.
The step are same as using AVplayer to play music, but the ULR no Album ID.
Run the playground code and then see video at the right side
— Using SFSafariview.controller to see the webpage.
import SafariServices
import PlaygroundSupport
let url = URL(string: "https://www.facebook.com/profile.php?id=100086358262943")
let controller = SFSafariViewController(url: url!)
PlaygroundPage.current.liveView = controller
The first is import “SafariService” and select which webpage would like to display.