GithubHelp home page GithubHelp logo

apivideo / api.video-swift-live-stream Goto Github PK

View Code? Open in Web Editor NEW
29.0 5.0 13.0 734 KB

Swift RTMP live stream client for iOS. Made with ♥ by api.video

Home Page: https://api.video

License: MIT License

Swift 96.14% Ruby 3.86%
swift video ios live-streaming-videos live-streaming library h264 h264-encoder livestream

api.video-swift-live-stream's Introduction

badge   badge   badge

Swift RTMP live stream client for iOS

api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.

Table of contents

Project description

This module is an easy way to broadcast RTMP live stream to api.video platform

Getting started

Installation

Swift Package Manager

In the Project Navigator select your own project. Then select the project in the Project section and click on the Package Dependencies tab. Click on the "+" button at the bottom. Paste the below url on the search bar on the top right. Finaly click on "Add package" button.

https://github.com/api.video-swift-live-stream

Or add this in your Package.swift

  dependencies: [
        .package(url: "https://github.com/api.video-swift-live-stream.git", from: "1.4.3"),
    ],

Cocoapods

  1. Add the following entry to your Podfile:
pod 'ApiVideoLiveStream', '1.4.3'
  1. Then run pod install
  2. Don’t forget to import ApiVideoLiveStream in every file you’d like to use api.video live stream library

Carthage

github "apivideo/ApiVideoLiveStream.swift" ~> 1.4.3

Permissions

To be able to broadcast, you must update Info.plist with a usage description for camera and microphone

...
<key>NSCameraUsageDescription</key>
<string>Your own description of the purpose</string>
<key>NSMicrophoneUsageDescription</key>
<string>Your own description of the purpose</string>
...

Code sample

  1. In ViewController.swift import the library
import ApiVideoLiveStream
  1. Create a ApiVideoLiveStream object with your default audio and video configuration
class ViewController: UIViewController {
    var liveStream:  ApiVideoLiveStream?
    @IBOutlet var viewCamera: UIView!
    override func viewDidLoad() {
        super.viewDidLoad()
        let audioConfig = AudioConfig(bitrate: 32 * 1000)
        let videoConfig = VideoConfig(bitrate: 2 * 1024 * 1024, resolution: Resolutions.RESOLUTION_720, fps: 30)
        do {
            liveStream = try ApiVideoLiveStream(initialAudioConfig: audioConfig, initialVideoConfig: videoConfig, preview: preview)
        } catch {
            print (error)
        }
    }
}
  1. Start your live stream with startStreaming
liveStream?.startStreaming(streamKey: "YOUR_STREAM_KEY")

Alternatively, you can use startStreaming url parameter to set the URL of your RTMP server.

Plugins

api.video sdk is using external library

Plugin README
HaishinKit https://github.com/shogo4405/HaishinKit.swift

FAQ

If you have any questions, ask us here: https://community.api.video . Or use Issues.

Also feel free to test our Sample app.

api.video-swift-live-stream's People

Contributors

anthony-dantard avatar bluebazze avatar cedricmontet avatar dougsillars avatar erikkai avatar kodypeterson avatar olivierapivideo avatar romainpetit1 avatar thibaultbee avatar titozzz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

api.video-swift-live-stream's Issues

Stop Streaming flow & onDisconnect

Summary

Noticed that the callback onDisconnect is not being called when executing stopStreaming.
Is this intentional? Or an error?

Motivation

My users can only stream inside of a time based window. Meaning they will get disconnected when the time reaches the end time of that predefined time window. In order to accommodate this on mobile. When the end time is reached, the live stream will shut down and close the live stream page. Meaning i gotta know when the connection have been closed before i close the stream view.

Problem

In the stopStreaming method
The rtmpConnection.close() might go async at some point.
Meaning the event listeners will get removed before the connection is actually closed.
Or
rtmpConnection.close() might not trigger the rtmpStatusHandler at all for some reason.

Solution

Have a private enum that contains the status that we want the live stream to be in.
Meaning in startStreaming, we set this variable to "streaming".
So if the connection fails, we know if the user wants the stream and we can retry the connection.
In stopStreamingwe set the enum to "stopped". When the rtmpStatusHandler reaches RTMPConnection.Code.connectClosed.rawValue we can first onDisconnect and afterwards check the enum, and then remove the event listeners.

Can make a pr. But want a go ahead first.

[Feat]: Multiple cam request

Version

last

Environment that reproduces the issue

iphone 15 pro

Use case description

Thanks for the sample application, when starting live broadcast; How can I start with the rear camera turned on?

Proposed solution

No response

Alternative solutions

No response

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.