[how fast development of a complete iOS live app] (play chapter)

Preface

Before you read this, if you don’t know the principles of live broadcast, check out the previous article on how to develop a full iOS live app

The development of a live app, integrated ijkplayer success, even if the completion of half of the live broadcast of the project, as long as there are pull flow URL, you can broadcast live!

This article is mainly on the live app, takes a very important open source framework used in the ijkplayer, and then the integrated framework for most beginners is quite difficult, so this article mainly teach you to solve all kinds of integrated pit [ijkplayer] met.

Many articles, may explain how to do, I pay more attention to explain why to do so, we have what do not understand, you can also put forward a lot.

If you love my article, I can focus on micro-blog: Seemygo Yuan Zheng, Zheng Yuan can also be Seemygo, we understand the iOS training course. The follow-up will be more updates, have any questions, welcome message Book Jane Zheng…

Effect

[how fast development of a complete iOS live app] (play chapter)
live.Gif

I. Basic Knowledge

README.md file: a description file for the framework that describes how the framework is used

Compiler: program before it is executed, the need for a special compilation process, the program is compiled into machine language file, the runtime does not need translation, so the compiler language program execution efficiency is high, such as OC, C, C++

Explanatory language: programs that do not need to be compiled, interpreted at run time, and translated when each statement is executed. In this way, interpreted languages need to be translated one line at a time, which is inefficient

The difference between interpreted language execution and compiled language execution:

  • Interpreted languages are parsed from line to line. If there is an error, they will not be executed, and the next line will be executed directly.
  • Compiled language, as long as there is a mistake, you can not compile, a line can not be executed.

Scripting language: an analytic language that must be parsed by an interpreter to translate its lines into machine recognizable instructions and executed in sequence.

  • Python: scripting language, suitable for network application development, is conducive to development efficiency, and now it is becoming more and more powerful
  • PHP: server-side scripting language, suitable for dynamic web sites
  • JS: interpreted as execution language in the browser as a scripting language for the client,
  • Shell: operating system scripting languages, generally referred to as command lines used in Unix/Linux
  • Compiled language. The executable file is binary. The script language is interpreted and executed, and the executable file is text

Shell interpreter: shell is a command line interpreter, equivalent to the windows CMD, between the kernel and the user, responsible for passing user instructions to the kernel and returning the execution results to the user

  • The default Unix has shell, and the OS is based on Unix, so OS comes with shell.

Bash: Bash is a version of the shell interpreter, and there are many versions of shell, just like people and people from different countries.

  • Cattle programmers see bad Shell interpreter, they will re write a set, and gradually formed some standards, commonly used Shell interpreter has so many kinds, SH, bash, CSH and so on

Shell: usually we say “shell”, referring to the shell scripting language, not the shell interpreter.

  • When writing shell, the first line must specify which shell system needs the interpreter to explain your shell script, such as: #! /bin/bash, use bash parsing script language
  • When to use the shell command, such as some system commands often need to use, you can encapsulate the command to a script file, and then do not have to knock again, the direct implementation of scripting language.
  • For example, ijkplayer downloads ffmpeg with script files, because downloading ffmpeg requires a lot of commands and is encapsulated in the script file.
  • When importing some third party framework, often need to use some commands, they are typically packaged into a script file, as long as after executing the script will automatically execute the command frame integration of third party.

Sh:sheel script file suffix

Two, Download ijkPlayer

  • Go to the B station, get the GitHub home page, find the ijkplayer project, download the source code, ijkplayer, download the address
  • Open Demo, check the usage, general learning third party library, are first check Demo
    [how fast development of a complete iOS live app] (play chapter)
    Snip20160825_4.png

Three, compile the steps of ijkPlayer

1, find ijkPlayerMediaDemo and run

  • Prompt’libavformat/avformat.h’, file, not, found
[how fast development of a complete iOS live app] (play chapter)
bug1.png

Reason: because libavformat is the library in ffmpeg, and ijkplayer is based on the library of ffmpeg, so you need to import ffmpeg

Solution: check the ijkplayer README.md, general instructions.

[how fast development of a complete iOS live app] (play chapter)
script.Png

The init-ios.sh script: download the ffmpeg source code

  • To see how the script works, check out what you’ve written before, take you into the script world, ijkplayer’s [init-ios.sh] script analysis, and analyze exactly what the init-ios.sh script has done.

How do I execute the init-ios.sh script file?

  • Step 1: find the init-ios.sh script file
[how fast development of a complete iOS live app] (play chapter)
finds the init-ios.sh file.Png
  • Step two: open the terminal and CD into the directory of ijkplayer-master
[how fast development of a complete iOS live app] (play chapter)
enters the init-ios.sh directory.Png
  • Note that this folder is CD
[how fast development of a complete iOS live app] (play chapter)
CD ijkplayer-master.png
  • Step three: enter./init-ios.sh and execute the current script.
[how fast development of a complete iOS live app] (play chapter)
executes init-ios.sh.png
  • After you execute the script, you’ll see that there is ffmpeg in ijkplayer
After [how fast development of a complete iOS live app] (play chapter)
executes the script,.Png

2, download the good ffmpeg source code, once again run Demo

  • Found or reported’libavformat/avformat.h’, file, not, found error
  • Reason: the implementation of init-ios.sh, just download the source code, but the source code did not participate in the compiler, you need to compile the source code to.A files, Demo dependent on the IJKMediaPlayer Library
[how fast development of a complete iOS live app] (play chapter)
Demo source code.Png
  • Open the IJKMediaPlayer library, view the source code
[how fast development of a complete iOS live app] (play chapter)
IJKMediaPlayer project location.Png
  • Open the IJKMediaPlayer library
    [how fast development of a complete iOS live app] (play chapter)
    IJKMediaPlayer source code.Png
  • Right click to see that the libraries in FFMPEG are red, indicating that there is no
    [how fast development of a complete iOS live app] (play chapter)
    Snip20160829_23.png
  • Solution: check out ijkplayer’s README.md
[how fast development of a complete iOS live app] (play chapter)
compiles ffmpeg.png

Compiling the ffmpeg Library

  • Step 1: enter the directory of the script file,
    , [how fast development of a complete iOS live app] (play chapter),
    , CD, ios.png
  • Step two: the implementation of./compile-ffmpeg.sh clean two step function: delete some files and folders, prepare for the compiled ffmpeg.sh, when compiling ffmpeg.sh, will automatically create those files just delete the file name, in order to avoid conflict, so in the ffmpeg.sh compiler before deleting will automatically create a folder or file
[how fast development of a complete iOS live app] (play chapter)
Snip20160828_19.png
  • Step three: execute./compile-ffmpeg.sh all, really compile the ffmpeg libraries of each platform, and generate the generic library for the platform
[how fast development of a complete iOS live app] (play chapter)
executes./compile-ffmpeg.sh all

Before executing compile-ffmpeg.sh all

[how fast development of a complete iOS live app] (play chapter)
,.Png before Compilation

After the implementation of compile-ffmpeg.sh all

[how fast development of a complete iOS live app] (play chapter)
compiled.Png

3., running Demo again can be successful because the IJKMediaPlayer library gets into the ffmpeg Library

  • After compiling the ffmpeg, the IJKMediaPlayer library displays the
    [how fast development of a complete iOS live app] (play chapter)
    and successfully gets it to the ffmpeg library.Png
  • Cmd+r, Demo runs successfully
The [how fast development of a complete iOS live app] (play chapter)
Demo runs successfully..png

Four, how to integrate ijkplayer into your own project?

  • Note: the methods in ijkplayer’s README are troublesome, inconvenient to carry, and not recommended.
[how fast development of a complete iOS live app] (play chapter)
Snip20160830_9.png

1., recommend yourself IJKMediaPlayer packaged into a static library, in the import to their own projects.

  • How to package, please refer to, iOS integrated ijkplayer video live frame, written very well, not one by one details, but only the release version of the library.
  • I’ve packed my own ijkplayer version of two libraries, which are used for debugging and publishing (DEBUG and Release), and click download
  • Because the file is too large to upload GitHUb, uploaded to Baidu cloud

2. pull the ijkplayer library directly into your project,

  • If you debug, drag into the debug version of the ijkplayer library and, if you publish it, drag it into the release version of the ijkplayer Library
[how fast development of a complete iOS live app] (play chapter)
Snip20160829_5.png

3. import ijkplayer dependent library, you can see the specific ijkplayer README

[how fast development of a complete iOS live app] (play chapter)
Snip20160829_6.png
[how fast development of a complete iOS live app] (play chapter)
Snip20160829_7.png

Five, use ijkplayer live broadcast

Introduction to 1.ijkplayer usage

  • Ijkplayer usage is relatively simple, in fact, as long as there is live address, you can live
  • Note: the best testing, more cards, the simulator is not smooth, there is no real problem

2. grab data

  • Caught a lot of live app data, found that the quality of the guest anchor is the highest.
  • Ying Ke anchor url:http://116.211.167.106/api/live/aggregation? Uid=133825214& interest=1 uid= ID account, here is my account ID interest= in 1, said only see girls, haha drop-down refresh interface did not catch, a load of 200 data, ha ha
- (void) loadData URL NSString reflected off the data {/ / *urlStr = @ "http://116.211.167.106/api/live/aggregation? Uid=133825214& interest=1; / / AFHTTPSessionManager = [AFHTTPSessionManager manager] *mgr request data; mgr.responseSerializer = [AFJSONResponseSerializer serializer]; mgr.responseSerializer.acceptableContentTypes [NSSet setWithObjects:@ =" text/plain ", nil] [mgr GET:urlStr parameters:nil progress:nil; success:^ (NSURLSessionDataTask * _Nonnull task NSDictionary * _Nullable responseObject) {_lives =" lives "[YZLiveItem mj_objectArrayWithKeyValuesArray:responseObject[@"; [_tableView reloadData];} failure:^ (NSURLSessionDataTask * _Nullable task NSError * _Nonnull error) {NSL Og (@ "% @", error);}];}

3. get streaming URL, live

  • IJKFFMoviePlayerController: used for live broadcast
- (void) viewDidLoad viewDidLoad] self.view.backgroundColor {[super; [UIColor = whiteColor]; / / set for live pictures NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@ http://img.meelive.cn/%@, _live.creator.portrait]] [self.imageView sd_setImageWithURL:imageUrl; placeholderImage:nil] NSURL *url; / / pull stream address = [NSURL URLWithString:_live.stream_addr]; / / create IJKFFMoviePlayerController: designed to live incoming pull flow address. IJKFFMoviePlayerController * playerVc [[IJKFFMoviePlayerController alloc] = initWithContentURL:url withOptions:nil]; / / prepareToPlay] / / [playerVc ready to play; strong references, anyway destroyed _player = playerVc; playerVc.vie W.frame = [UIScreen mainScreen].bounds; [self.view insertSubview:playerVc.view atIndex:1];}

4. end play

  • Interface does not play, must remember to end the play, otherwise it will be reported memory overflow
[how fast development of a complete iOS live app] (play chapter)
memory bug.png
- (void) viewWillDisappear: (BOOL) animated {[super viewWillDisappear:animated]; / / interface disappeared, remember to stop playing the [_player pause]; [_player stop];}

Concluding remarks

The follow-up will also update more information about the live broadcast, hoping to teach every friend from scratch to do a live app, and Demo will gradually improve.
Demo click download

  • Since the FFMPEG library is larger, about 100M.
  • Originally wanted to upload all the code, upload 1 hours, not yet successful, gave up.
  • To provide an alternative, you need to import the IJKPlayer library specific steps yourself:
  • After you download Demo, open the YZLiveApp.xcworkspace problem
[how fast development of a complete iOS live app] (play chapter)
opens the YZLiveApp.xcworkspace problem
  • Pod install can solve
[how fast development of a complete iOS live app] (play chapter)
Snip20160830_12.png
  • Download the jkplayer library and click download
  • Jkplayer directly into the same directory with Classes, direct operation of the program, you can succeed
[how fast development of a complete iOS live app] (play chapter)
drags ijkplayer to.Png at the same level as Classes
  • Note that you don’t need to open the project and drag jkplayer into the project, but copy the jkplayer library directly to the same directory as Classes.
  • Error demonstration: do not operate like this
[how fast development of a complete iOS live app] (play chapter)
Snip20160830_14.png