Live Streaming in Swift

廉价感情. 提交于 2019-12-06 06:46:46

问题


I need to create a live streaming application in SWIFT

Tried many ways using AVFoundation framework (AVPLayer & AVPlayeritem) but didn't work

It's audio only so I don't want to do it in the webview way.

Thanks in advance


回答1:


You might try leveraging the VideoCore library that wraps these frameworks into a complete streaming package. With this package, you can readily start publishing with little effort. Take the following for consideration (replicated from their example projects):

To initiate a connection (Obj-C):

VCSimpleSession *sess = [[VCSimpleSession alloc] initWithVideoSize:CGSizeMake(width, height) frameRate:frameRate bitrate:bitrate] useInterfaceOrientation:YES];
sess.delegate = self;

To initiate a connection (Swift):

var sess:VCSimpleSession = VCSimpleSession(videoSize: CGSize(width: width, height: height), frameRate: frameRate, bitrate: bitRate, useInterfaceOrientation: false)
sess.delegate = self;

Utilize the event handler (Obj-C):

- (void) connectionStatusChanged:(VCSessionState) state{
   if(state==VCSessionStateStarting){
      // connecting to destination host
   }
   else if(state==VCSessionStateStarted){
     // connected, streaming has begun
   }
   // ... etc
}

Utilize the event handler (Swift):

func connectionStatusChanged(sessionState: VCSessionState) {
        switch session.rtmpSessionState {
        case .Starting:
            // initiating connection

        case .Started:
            // connected

        default:
           // connect
        }
    }

Alternatively, there are paid SDK's out there that you can get support on like Wowza's GoCoder SDK. A slew more options and a stable infrastructure.

Thanks

Matt



来源:https://stackoverflow.com/questions/25960563/live-streaming-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!