Demonstrates how to build a live broadcast app(Swift 3)

Related tags

Video Live
Overview

This project is to demonstrate how to build a live broadcast app. It include these features:

  • Create a room to broadcast your live stream
  • Join a room to watch the live
  • Send likes, gifts, and comments

image  image

Introduction

How to run

1. Nginx RTMP server

You need to can set up your own rtmp server, the guidance can be found here:

2. WebSocket server

Just go to the live-server folder, run npm install, then start the server by node app.js

3. iOS client

Go to the live-ios folder, run pod install(must use cocoapods 0.39.0)

In Config.swift, update the server url:

struct Config {
    static var rtmpPushUrl = "rtmp://139.196.179.230/mytv/"
    static var rtmpPlayUrl = "rtmp://139.196.179.230/mytv/"
    static var serverUrl = "http://139.196.179.230:3000"
}

The app can also run on a simulator, but to broadcast, you need to run it on a real device.

Tutorial

1. Live streaming

The basic live streaming flow is:

broadcaster -> rtmp -> media server -> cdn -> rtmp or hls -> audience

For the simplest case, we don't need a cdn server, then the flow will be:

broadcaster -> rtmp -> media server -> rtmp or hls -> audience

That is, the boadcaster push the live stream using the RTMP protocal to a media server, the audience pull the stream from the server using RTMP or HLS protocal.

Some explaination for RTMP and HLS:

  • RTMP: RTMP is used to stream audio, video or data and is originally a proprietary protocol introduced by Macromedia (owned by Adobe). The protocol is TCP-based and offers therefore persistent connections. In short, RTMP encapsulates MP3/AAC audio and MP4/FLV video multimedia streams.

  • HLS: HTTP Live Streaming is known as HLS. As the name implies, it is the media streaming communications protocol based on HTTP; developed by Apple as part of their QuickTime, Safari, OS X, and iOS products. How does it work? It breaks the overall stream into a sequence of small HTTP-based files (.ts: Transport Stream). These transport stream files are indexed in the file .m3u8. It is required to download first the .m3u8 playlist to play a live stream.

For the media server, there are serveral choices:

  • Adobe media server
  • Red5
  • Nginx RTMP module
  • crtmpserver

After setting up the server, you can test it using ffmpeg(install it by brew install ffmpeg).

  • push stream
ffmpeg -f avfoundation -framerate 30  -i "1:0" -f flv rtmp://server-url

p.s. Lots of live stream cloud already covers the media server and cdn parts. You just need to push/pull the stream from it.

2. iOS RTMP libs

There are serveral open source projects supporting RTMP, this project uses:

You can find the usage of these libs in their project pages.

3. Websocket server

This project uses socket.io to handle the client-server communication, the logic is very simple, on the server side:

var rooms = {}

io.on('connection', function(socket) {

  socket.on('create_room', function(room) {
    var roomKey = room.key
    rooms[roomKey] = room
    socket.roomKey = roomKey
    socket.join(roomKey)
  })

  socket.on('close_room', function(roomKey) {
    delete rooms[roomKey]
  })

  socket.on('disconnect', function() {
    if (socket.roomKey) {
      delete rooms[socket.roomKey]
    }
  })

  socket.on('join_room', function(roomKey) {
    socket.join(roomKey)
  })

  socket.on('upvote', function(roomKey) {
    io.to(roomKey).emit('upvote')
  })

  socket.on('gift', function(data) {
    io.to(data.roomKey).emit('gift', data)
  })
  
})

On the client side, it uses the socket.io swift client(https://github.com/socketio/socket.io-client-swift), the logic is also simple:

create, join, or close a room:

socket.on("connect") { data, ack in
    self.socket.emit("create_room", self.room)
}

socket.on("connect") { data, ack in
    self.socket.emit("join_room", self.room.key)
}

socket.disconnect()

publish likes and comments events:

socket.emit("upvote", room.key)
socket.emit("comment", [
    "roomKey": room.key,
    "text": text
])

listen likes and comments events:

socket.on("upvote") { data, ack in
    self.emitterView.emitImage(R.image.heart()!)
}
        
socket.on("comment") { data, ack in
    let comment = Comment(dict: data[0] as! [String: AnyObject])
    self.comments.append(comment)
    self.tableView.reloadData()
}
Comments
  • second launch crashed.

    second launch crashed.

    i have changed 123 in Config.swift and i run node app.js success and terminal display listening on port 3000... for the first time it works well.but second time it crashed like below: 123

    opened by DreamXiao 8
  • nginx.conf file

    nginx.conf file

    Could you please share your nginx.conf file? Because we are the noobies here and don't know anything about Nginx :( Just to mention that your app with your server runs perfect and i'm trying to make it on my own!

    opened by kwstasna 7
  • Not able to make an ipa file

    Not able to make an ipa file

    Hi, It is running successfully in simulator and device when connected to system.

    But I am unable to make ipa file at the time of build. It is showing me 4 error. Please check screenshot.

    Please help me to resolve the issue. screen shot 2017-06-28 at 4 33 32 pm

    opened by ricky3214 6
  • Latency issue

    Latency issue

    Hi, Thanks for sharing the great code. I try it with DigitalOcean server and choose the Singapore Data Center as it's closest to me.

    There's a problem with delay in the live video(Latency).

    Do you have any suggestion on hosting or configuration to do to reduce it to the minimum?

    Thanks

    opened by garudaonekh 6
  • Missing videocore pods?

    Missing videocore pods?

    Please help.. I ran the pod install and everything installed perfectly all dependencies. Opened the project and went to run on my device and I am getting errors.. ran multiple pod installs with success, but not sure why I am missing these files. I went to videoCore directly and copied the mixers folder in.. still no dice.. screen shot 2016-09-01 at 1 26 22 pm

    opened by SirSamShaw 6
  • Archive clang error at IJKMediaFramework

    Archive clang error at IJKMediaFramework

    ld: bitcode bundle could not be generated because '.../Live/live-ios/IJKMediaFramework.framework/IJKMediaFramework(IJKMediaPlayback.o)' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    I succeeded to run Live, but failed to archive it. Do you have any suggestion that I should do?

    opened by yasuradodo 4
  • App seems to be crashing when I try to create a room (start broadcasting) on a test phone

    App seems to be crashing when I try to create a room (start broadcasting) on a test phone

    Everything seems to work on simulator, I am able to start a broadcast room and find the room and start chatting and sending gifts in the room. However, when I load it to a test phone (iphone7), as soon as I click on the + to start a broadcast room, the app crashes.

    It seems that this is not successful in BroadcasterViewController: let videoConfiguration = LFLiveVideoConfiguration.defaultConfiguration(for: .medium3) I get a error "Protocol not available" Am I missing a step somewhere? Thank you so much!

    opened by maochenw 2
  • Bitcode bundle error while Archiving

    Bitcode bundle error while Archiving

    The project builds just fine, however when I try to archive it, I receive the following:

    ld: bitcode bundle could not be generated because '../pili-librtmp.framework/pili-librtmp(amf.o)' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture armv7

    I have a physical device connected (NOT a Simulator). I've set the enable_bitcode flags = NO at both the project and pod level. Nothing.

    opened by ctufaro 2
  • IJK player needs update

    IJK player needs update

    Hi,

    I had two issues when I used this:

    1. A stream video to B. A restarts streams. B can only see video no sound.
    2. No ARMV6 (Iphone 5, 5s) support.

    I solved both problems by getting the IJK player from original github and recompiling it.

    opened by San-Jeevan 2
  • Supported Languages

    Supported Languages

    Hello again. I was trying to make channels in chinese and greek characters but it doesnt work and it crashes in this line in the file AudienceViewController

    override func viewDidLoad() {
            super.viewDidLoad()
    
            player = IJKFFMoviePlayerController(contentURL: NSURL(string: Config.rtmpPlayUrl + room.key), withOptions: IJKFFOptions.optionsByDefault())
    
            player.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]  //in this line!!
            player.view.frame = previewView.bounds
            previewView.addSubview(player.view)
    
            player.prepareToPlay()
    
            socket.on("connect") {[weak self] data, ack in
                self?.joinRoom()
            }
    
        }
    
    

    Any idea how to make it support different characters?

    opened by kwstasna 2
  • error when creating archive

    error when creating archive

    Error face when create archive xcode version : 8.3

    OBJC_CLASS$IJKFFOptions”,referenced from: Objc-class-ref in streaming_play.o

    “_IJKMPMoviePlayerLoadStateDidChangeNotification”,referenced from: TFC8stratafy14streaming_play14viewAillAppearfSbR in streaming_play.o

    OBJC_CLASS$IJKFFMoviePlayerController”,referenced from: Objc-class-ref in streaming_play.o Symbol(s) not found for architecture armv7

    opened by Trushangpatel 1
  • Can't display video when join room

    Can't display video when join room

    I used server localhost struct Config {

    static var rtmpPushUrl = "rtmp://192.168.0.104:3000/live/"
    static var rtmpPlayUrl = "rtmp://192.168.0.104:3000/live/"
    static var serverUrl = "http://192.168.0.104:3000"
    

    }

    I created room in Device A. And then join room from Device B. But device B do not show video, It's only chat , send gift..

    Please, Can i help you how show it. Thank you

    opened by ishrek 0
  • Where do I get Config urls?

    Where do I get Config urls?

    struct Config {

    static var rtmpPushUrl = "rtmp://106.187.100.229/live/"
    static var rtmpPlayUrl = "rtmp://106.187.100.229/live/"
    static var serverUrl = "http://192.168.100.70:3000"
    

    }

    Where do I get the 3 urls?

    opened by albertml 1
Owner
Leo
I am now working as a consultant helping startups to build product. If you need any help, feel free to contact me. 🙂
Leo
A video composition framework build on top of AVFoundation. It's simple to use and easy to extend.

A high-level video composition framework build on top of AVFoundation. It's simple to use and easy to extend. Use it and make life easier if you are implementing video composition feature.

VideoFlint 1.4k Dec 25, 2022
Personal App that turned into "alpha released app"

Muubii Works on macos 11.0 and later* Installation Automatic install (recommended) Open Terminal. Paste the line below, once done check your applicati

Aayush 429 Jan 2, 2023
A lightweight app to play videos from the Files app in a better (dark) interface which avoids losing your playback position.

Playerly Playerly is a very lightweight Swift app that allows you to select a file (video or movie) from the built in Document Browser, and play it in

Julian Schiavo 28 Dec 3, 2022
Personal App that turned into "alpha released app"

Native-Youtube Personal App that turned into "alpha released app" Requirements: MacOS 12.0 or above A working google account Usage Download the univer

Aayush 426 Dec 28, 2022
The front-end of youtube iOS app developed using swift 5

Youtube-Front-end-iOS The front-end of youtube iOS app developed using swift 5 UIs 1)-The UI that corresponds to Home Tab bar "The first View " The fi

null 1 Nov 28, 2021
📱iOS app to extract full-resolution video frames as images.

Frame Grabber is a focused, easy-to-use iOS app to extract full-resolution video frames as images. Perfect to capture and share your favorite video mo

Arthur Hammer 315 Dec 17, 2022
A fully functional short video app project.Record a six secends video while playing prank sounds.

prankPro A fully functional short video app project How to Install 1. use coconapod to init your xcode environment. 2. change the app-keys in `applica

huijimuhe 258 Jun 19, 2022
A simple iOS app similar to iTunes where you can view details of your favorite movies, songs and audio books.

Popcorn Adventure This is an iOS app developed by Arthur Tristan M. Ramos who has taken the Appetiser iOS Coding Challenge. Design Pattern The design

Arthur Tristan M. Ramos 0 Dec 11, 2021
Simple macOS app that applies Apple's Person Segmentation algorithm to a video.

Simple macOS app that applies Apple's Person Segmentation algorithm to a video.

Fabio 5 Dec 9, 2022
YoutubeKit is a video player that fully supports Youtube IFrame API and YoutubeDataAPI for easily create a Youtube app

YoutubeKit YoutubeKit is a video player that fully supports Youtube IFrame API and YoutubeDataAPI to easily create Youtube applications. Important Ref

Ryo Ishikawa 555 Dec 28, 2022
iOS Video Conferencing SDK & Sample App

?? 100ms SDK & Sample App ?? Here you will find everything you need to build experiences with video using 100ms iOS SDK. Dive into our SDKs, quick sta

100ms 28 Dec 14, 2022
Dedicated storyboarding iPad app for video content creators.

CS3217 - Storyteller Final Project for CS3217: Software Engineering for Modern Application Platforms By: Marcus, Pan Yongjing, and Tian Fang Overview

Marcus Ng 0 Nov 29, 2021
A fan-made passion project. iOS app designed to keep track of data mined from Animal Crossing: New Horizons

DataCrossing A fan-made passion project. iOS app designed to keep track of data

Natalie 1 Jan 10, 2022
Valorem-demo - Demonstration code and video of Valorem, a bespoke portfolio recommendation platform to be created as an iOS mobile app.

valorem-demo Demonstration code of Valorem, a bespoke portfolio recommendation platform to be created as an iOS mobile app. The included code demonstr

Marcus Deans 1 Mar 4, 2022
📺 A news app using YouTube playlists, built with React Native

NewsWatch-React-Native A YouTube News app for iOS, made with React-Native. Enjoy watching your daily news. Screencast: This project was bootstrapped w

brad oyler 156 Jun 8, 2022
This Google Cast demo app shows how to cast videos from an iOS device in a way that is fully compliant with the Cast Design Checklist.

CastVideos-ios (reference iOS sender app) This Google Cast demo app shows how to cast videos from an iOS device in a way that is fully compliant with

Google Cast 168 Jan 6, 2023
Catalyst example of a grid-based video app that opens videos in secondary windows

Simple Catalyst example (Mac idiom) of a grid-based app populated with videos. On macOS, double-clicking a video opens it in a new playback window. Keyboard navigation is fully supported via the UIKit Focus Engine.

Steven Troughton-Smith 19 Dec 8, 2022
Telemat ist eine einfache Single-Screen-Streaming-App für tvOS

Telemat tvOS Basierend auf der ursprünglichen Idee von https://github.com/noestreich/Telemat1000_iPad ist Telemat tvOS eine tvOS APP, mit der ein schn

Oliver Michalak 15 Oct 7, 2022
iCook's official tvOS app

iCook tvOS App A tvOS app that plays iCook TV videos. Quick Start Run the following commands to install dependencies: make bootstrap Production Setup

Polydice, Inc. 67 Nov 17, 2022