Giter Club home page Giter Club logo

facebook-live-ios's Introduction

 Facebook Live iOS

A custom Swift utility "FBSDKLiveVideo" to stream Facebook Live videos on iOS.

App Store

Example

The following example would create a full-screen live video preview that is started when the user taps the trigger button linked in your Storyboard.

class ViewController: UIViewController {
    
    var liveVideo: FBSDKLiveVideo!

    override func viewDidLoad() {
        super.viewDidLoad()
      
        // Create the live video service
        liveVideo = FBSDKLiveVideo(
            delegate: self,
            previewSize: self.view.bounds,
            videoSize: CGSize(width: 1280, height: 720)
        )
        
        // Optional: Configure the live-video (see the source for all options)
        liveVideo.privacy = .me // or .friends, .friendsOfFriends, .custom
        liveVideo.audience = "me" // or your user-id, page-id, event-id, group-id, ...
        
        // Optional: Add the preview view of the stream to your container view.
        myView.addSubView(liveVideo.preview)
    }
    
    @IBAction func recordButtonTapped() {
        liveVideo.start()
    }    

    @IBAction func stopButtonTapped() {
        liveVideo.stop();
    }

    @IBAction func adBreakButtonTapped() {
        liveVideo.adBreakStartNow = true
        liveVido.update();
    }

    @IBAction func deleteButtonTapped() {
        liveVido.delete();
    }
}

extension ViewController: FBSDKLiveVideoDelegate {
    func liveVideo(_ liveVideo: FBSDKLiveVideo, didStartWith session: FBSDKLiveVideoSession) {
        // Live video started
    }

    func liveVideo(_ liveVideo: FBSDKLiveVideo, didStopWith session: FBSDKLiveVideoSession) {
        // Live video ended
    }

    func liveVideo(_ liveVideo: FBSDKLiveVideo, didErrorWith: Error) {
        // Live video errored
    }

    func liveVideo(_ liveVideo: FBSDKLiveVideo, didChange sessionState: FBSDKLiveVideoSessionState) {
        // Live video changed session state
        // One of: .none, .previewStarted, .starting, .started, .ended, .error
    }

    func liveVideo(_ liveVideo: FBSDKLiveVideo, didAdd cameraSource: FBSDKLiveVideoSession) {
        // New camera source added to the stream
    }

    func liveVideo(_ liveVideo: FBSDKLiveVideo, didUpdate session: FBSDKLiveVideoSession) {
        // Live video was updated through update()
    }

    func liveVideo(_ liveVideo: FBSDKLiveVideo, didDelete session: FBSDKLiveVideoSession) {
        // Live video was deleted through delete()
    }
}

Build

  • Run pod install to install the required dependencies (Facebook SDK + VideoCore)
  • Open the facebook-live-ios-sample.xcworkspace file in Xcode
  • Change the app-id inside the Info.plist to match your app. Ensure to configure the App-ID correctly
  • Run the project on your iOS device! By default, it will only start a live-stream to your private audience ("Only me")

License

MIT - Try it out, modify it, use it!

Author

Hans Knöchel (@hansemannnn)

Contributions

Code contributions are greatly appreciated, please submit a new Pull Request!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.