ksvc / KSYLive_iOS

金山云直播SDK [ iOS推流+播放 ]融合版 支持美颜滤镜(Beauty Filter)、美声(Beauty Voice)、软硬编(Software/Hardware Encoder) 、网络自适应(Network Auto Adapt)、混音(Audio Mixer)、混响(Reverb)、画中画(PIP)
https://github.com/ksvc/KSYLive_iOS/wiki
941 stars 271 forks source link

RTMP broadcasting when the app goes in background #184

Open jsfan3 opened 4 years ago

jsfan3 commented 4 years ago

Thank you so much for your great library. I tried to use it to make a live streaming: it works properly.

The moment the app goes into the background, however, the RTMP stream stops. What can I do to make the streaming continue even when the app goes in the background? When recording events, it is essential that the streaming is not accidentally interrupted by a phone call or another app.

Thank you for your support.

This is my code:

#import "net_informaticalibera_test_rmtpclient_RMTPBroadcastNativeImpl.h"
#import <GPUImage/GPUImage.h>
#import <libksygpulive/KSYGPUStreamerKit.h>
#import "CodenameOne_GLViewController.h"
#import "cn1_globals.h"
#import "com_codename1_io_Log.h"
#import "com_codename1_ui_CN.h"

@implementation net_informaticalibera_test_rmtpclient_RMTPBroadcastNativeImpl

KSYGPUStreamerKit* kit = nil;
NSURL* url = nil;
UIView* myView = nil;

-(void)startBroadcast{
    dispatch_sync(dispatch_get_main_queue(), ^{
        NSLog(@"Value of url = %@", url.absoluteString);
        [kit.streamerBase startStream:url];
    });
}

-(void)switchCamera{
    dispatch_sync(dispatch_get_main_queue(), ^{
        [kit switchCamera];
    });
}

-(void*)getCameraPreview:(NSString*)param{
    dispatch_sync(dispatch_get_main_queue(), ^{
        [[UIApplication sharedApplication] setIdleTimerDisabled:YES];

        url = [[NSURL alloc] initWithString:param];
        CGSize size = [UIScreen mainScreen].bounds.size;
        myView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)];
        kit = [[KSYGPUStreamerKit alloc] initWithDefaultCfg];
        [kit startPreview:myView];
    });
    return myView;
}

-(void)stopBroadcast{
    dispatch_sync(dispatch_get_main_queue(), ^{
        [kit.streamerBase stopStream];
    });
}

-(BOOL)isSupported{
    return YES;
}

@end
ducbm-belive commented 3 years ago

hello, have you found the solution for this? I just met this issue :D Tks

jsfan3 commented 3 years ago

@ducbm-belive No, I didn't find a solution