Search code examples
iosuiviewstreaminglivevideocore

Fill a ui view with live streaming video using VideoCore library


I am using VideoCore library to capture and to live stream video to a server. I am using a square uiview to monitor the live stream on my app. But I could not completely fill the view with my live streaming video output. Any help is very much appreciated. Thanks. I am new to iOS development.

Here's my code:

ViewController.h

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <AVFoundation/AVFoundation.h>
#import "VCSimpleSession.h"
#import <CoreMedia/CoreMedia.h>

@interface ViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UIView *previewview;

ViewController.m:

#import "ViewController.h"
#import "VCSimpleSession.h"
@interface ViewController ()<VCSessionDelegate>


@end

VCSimpleSession *mysession;

UIImagePickerController *picker;

int *flag;

@implementation ViewController

@synthesize mybutton;

- (void)viewDidLoad
{
    [super viewDidLoad];
    flag = 0;
    self.textfield.autocorrectionType = UITextAutocorrectionTypeNo;

    mysession.delegate = self;

    self.previewview.hidden = NO;
    self.mybutton.hidden = NO;
    self.textfield.hidden = NO;

    [self.mybutton setBackgroundColor:[UIColor greenColor]];
    [self.mybutton setTitle:@"Start streaming" forState:UIControlStateNormal];
    mysession = [[VCSimpleSession alloc]initWithVideoSize:CGSizeMake(1280, 720) frameRate:30 bitrate:100000 useInterfaceOrientation:YES];

    mysession.previewView.frame = self.previewview.bounds;

    [self.previewview addSubview:mysession.previewView];
}

Solution

  • I got my my problem solved.

    In this line instead of 1280,720

    mysession = [[VCSimpleSession alloc]initWithVideoSize:CGSizeMake(1280,720) frameRate:30 bitrate:100000 useInterfaceOrientation: YES];
    

    I entered 480,850

    mysession = [[VCSimpleSession alloc]initWithVideoSize:CGSizeMake(480,850) frameRate:30 bitrate:100000 useInterfaceOrientation: YES];
    

    This got my problem solved. Now my ui view is filled with live camera feed.