1

I'm interested in building a iOS application similar to wynk.The app will be having a list of songs. On clicking any option, it will start streaming that music file from the server. I don't want to use any third Party API. Any help/ suggestion will be of great help. I'm using xCode 8.0 with swift 3.

Peeyush karnwal
  • 622
  • 7
  • 24

2 Answers2

2

Apple provides HTTP Live Streaming (HLS) for audio/video streaming: https://developer.apple.com/streaming/,

At the start of the streaming session, the client downloads a master .m3u8 playlist file containing the metadata for the various sub-streams which are available. Then decides what to download from the media files available, based on predefined factors such as device type, resolution, data rate, size, etc.

Apple provides sample code on how to play and persist HTTP Live Streams hosted on remote servers: https://developer.apple.com/library/content/samplecode/HLSCatalog/Listings/HLSCatalog_AssetListTableViewCell_swift.html#//apple_ref/doc/uid/TP40017320-HLSCatalog_AssetListTableViewCell_swift-DontLinkElementID_4

also check this answer on HLS here, you'll get the whole picture: HTTP LIve Streaming

AVFoundation for playback https://developer.apple.com/av-foundation/

import AVFoundation
import UIKit

class ViewController: UIViewController {

    override func viewDidAppear(animated: Bool) {
        let videoURL = NSURL(string: "your_video_url")
        guard let player = AVPlayer(URL: videoURL) else { return }
        let playerLayer = AVPlayerLayer(player: player)
        playerLayer.frame = self.view.bounds
        self.view.layer.addSublayer(playerLayer)
        player.play()
    }
}
Community
  • 1
  • 1
Oleh Zayats
  • 2,423
  • 1
  • 16
  • 26
0

You can use AVPlayer which is a controller object used to manage the playback and timing of a media asset. It provides the interface to control the player’s transport behavior such as its ability to play, pause, change the playback rate, and seek to various points in time within the media’s timeline. You can use an AVPlayer to play local and remote file-based media, such as QuickTime movies and MP3 audio files, as well as audiovisual media served using HTTP Live Streaming.

abdullahselek
  • 7,893
  • 3
  • 50
  • 40