This is the 28th day of my participation in the August Text Challenge.More challenges in August


My column

  1. Explore the underlying principles of iOS
  2. Summary of iOS underlying principles of exploration

preface

The last part of the live series, broadcast on mobile. Please refer to the previous two parts if you need them:

  • Setting up the server
  • Push the flow section

I choose to use iJkPlayer IJKMediaFramework third-party library integration and use. This article is very detailed and can be integrated into your project step by step according to steps.

Next, in controller

#import <IJKMediaFramework/IJKMediaFramework.h>
Copy the code

configuration

Then, configure the address of the project’s pull flow

/ / this is pull flow address, you can in the server configuration # define INT_Strean @ "RTMP: / / 192.168.1.109:1935 / live/asd." "Copy the code

Next, you define the view that displays the pull stream and the configuration related to frame rate and playback.

@property (nonatomic, strong) IJKFFMoviePlayerController *player;
@property (nonatomic, strong) UIView *playView;
Copy the code
#pragma mark - (void)viewWillAppear:(BOOL) Animated {[super viewWillAppear:animated]; // Start playing [self.player prepareToPlay] when attempting to display; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playStatuDidchange: name:IJKMPMoviePlayerPlaybackStateDidChangeNotification object:self.player]; } # pragma mark - view has disappeared - (void) viewDidDisappear: (BOOL) animated {[super viewDidDisappear: animated]; [self.player shutdown]; [[NSNotificationCenter defaultCenter] removeObserver:self name:IJKMPMoviePlayerPlaybackStateDidChangeNotification object:self.player]; }Copy the code
- (void)viewDidLoad { [super viewDidLoad]; [IJKFFMoviePlayerController setLogReport:YES]; [IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_DEBUG]; [IJKFFMoviePlayerController checkIfFFmpegVersionMatch:YES]; _pp = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size. Width * 0.49, [UIScreen mainScreen] bounds. Size. Height * 0.49)]; _pp. Center = CGPointMake (self. View. Center. * 0.5 x, the self. The center. The y); [self.view addSubview:_pp]; IJKFFOptions *options = [IJKFFOptions optionsByDefault]; [options setPlayerOptionIntValue:1 forKey:@"videotoolbox"]; / / frame rate (FPS) (you can change, confirm the standard frame rate will lead to great are not synchronized, so can only be set to 15 or 29.97) [options setPlayerOptionIntValue: 29.97 forKey: @ "r"); // -vol -- set the volume to 256. (to set into two times the volume when the input to 512 and so on [options setPlayerOptionIntValue: 512 forKey: @ "vol"]. NSURL *url = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] objectForKey:@"intURL"]]; _player = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:options]; UIView *playView = [self.player view]; UIView *displayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size. Width * 0.49, [UIScreen mainScreen] bounds. Size. Height * 0.49)]; DisplayView. Center = CGPointMake (self. View. Center. * 1.5 x, the self. The center. The y); self.playView = displayView; self.playView.backgroundColor = [UIColor blackColor]; [self.view addSubview:self.playView]; playView.frame = self.playView.bounds; playView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self.playView insertSubview:playView atIndex:1]; [_player setScalingMode:IJKMPMovieScalingModeAspectFit]; [_player setShouldAutoplay:YES]; / / automatically play self. View. AutoresizesSubviews = YES; // Automatically update the self-view sizeCopy the code

Finally, we can manually start and pause playback by using the following methods:

[_player play]; // Start play method [_player pause]; // Pause the playback methodCopy the code

Reference article:

  • Set up live broadcast server on Mac Nginx+ RTMP

  • Mac live server Nginx is configured to support HLS

  • Use nginx and RTMP plug-in to build live video and vod server

In fact, I want to do the whole set of live broadcasting by myself (including mobile terminal and service terminal), but I have been confused before. Recently, I happened to see the above three blogs, which instantly relieved me of many doubts. Share it and hope we can study it together. I’ll post a full tutorial later when IT’s done.

Supplementary problem record

The iOS side

Linker Command failed with exit code 1 (USE-V to see Invocation) when engineering invocation failed

In current Xcode7, the solution is: select project -> Double click ->target->buildSeting-> search BITCODE, default is Yes, change to no. Rerun BitCode is what

The server side

Error: Nginx starts with pid missing error

Nginx: [error] open () "/ usr/local /var/ run/nginx. Pid "failedCopy the code

Solution:

sudo nginx -c /usr/local/etc/nginx/nginx.conf

sudo nginx -s reload
Copy the code