SKrotkih / YTLiveStreaming

iOS open source framework to create live broadcasts and video streams on YouTube with YouTube Data API v3
MIT License
97 stars 45 forks source link
cocoapod cocoapods googlesignin moya swift swiftlint swiftpackagemanager swiftui video-stream xcode xcode-unit-tests youtube youtube-api-v3

YTLiveStreaming

YTLiveStreaming is an open source iOS framework to create live broadcasts and video streams on YouTube using YouTube Live Streaming API (YouTube Data API v3)

Requirements

Introduction

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.0+ is required to build YTLiveStreaming

To integrate YTLiveStreaming into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '13.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'YTLiveStreaming'
end

Then, run the following command:

$ pod install

Swift Package Manager

To integrate YTLiveStreaming package using Apple's Swift package manager

User guide

[YouTube Live Streaming API Reference](https://developers.google.com/youtube/v3/live/docs) 

import YTLiveStreaming

...

let input: YTLiveStreaming = YTLiveStreaming

...

// Get broadcasts list
let broadcastList = await input.getBroadcastListAsync()

// Get all events in different arrays of the LiveBroadcastStreamModel type
input.getAllBroadcasts(){ (upcomingEvents, liveNowEvents, completedEvents) in
   ...
}

// Get events separately:

// Get Ready to broadcast events
input.getUpcomingBroadcasts() { result in
      switch result {
          case .success(let upcomingEvents):
            ...
          case .failure(let error):
            ...
      }    
} 

// Get Live now broadcasts
input.getLiveNowBroadcasts() ( result in
      switch result {
          case .success(let  liveNowEvents):
              ...
          case .failure(let error):
              ...
      }
} 

// Get Completed broadcasts
input.getCompletedBroadcasts() ( result in
         switch result {
             case .success(let completedEvents):
                 ...
             case .failure(let error):
                 ...
         }
   } 

// Create Broadcast
input.createBroadcast(title, description: description, startTime: startDate, completion: { liveBroadcast in
   if let liveBroadcast = liveBroadcast {
      ...
   }
})

// Update of the existing broadcast: LiveBroadcastStreamModel
input.updateBroadcast(broadcast, completion: { success in
    if success {
       ...
    }      
})

// Start broadcast streaming video
input.startBroadcast(broadcast, delegate: self, completion: { streamName, streamUrl, _ in
   if let streamName = streamName, let streamUrl = streamUrl {
     completion(streamUrl, streamName)
   }
})

// Finish broadcast streaming video
input.completeBroadcast(broadcast, completion: { success in
   if success {
      ...
   }
})

// Delete all broadcast from the USER's account
if await input.deleteAllBroadcastsAsync() {
    // all broadcasts are deleted
}

// Delete broadcasts by IDs
if await input.deleteBroadcastsAsync(broadcastIDs) {
    // all broadcasts by IDs are deleted
}

// Delete broadcast by ID   
input.deleteBroadcast(id: broadcastId, completion: { success in
    if success {
       ...
    }
})

And some other public methods of the YTLiveStreaming class

Example of using YTLiveStreaming Framework

LiveEvents is an example of using the framework

Libraries Used

Note. Here were used the following things:

The project was created 11-11-2016

Changes history: 27.12.2022