Getting Serious on the Playground

I know, let’s write a streaming web radio application!

Don’t panic; this isn’t as scary as you think. We can get this running with shockingly little code. But let’s do so in a new playground. Close the current playground window, and use File > New > Playground to create a new playground. Call it WebRadioPlayground. Keep the line that says import UIKit, but delete the var str = "Hello, playground" line, and replace it with the following:

1: import​ ​AVFoundation
2: let​ url = ​URL​(string:
3: "http://www.npr.org/streams/aac/live1_aac.pls"​)
4: let​ player = ​AVPlayer​(url: url!)
5: player.play()

Nothing will happen just yet, but hang in there… ...

Get iOS 10 SDK Development, 1st Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.