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 = ​NSURL​(string:
3: "http://www.publicbroadcasting.net/wgvu/ppr/wgvufm.m3u"​)
4: let​ player = ​AVPlayer​(​URL​: url!)
5: player.play()

Nothing will happen just yet, but hang ...

Get iOS 9 SDK Development 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.