"How to quickly develop a complete iOS Live App" (play article)

Source: Internet
Author: User

Objective

Before reading this article, if you don't know how to live, check out the previous article on how to quickly develop a complete iOS Live App (rationale)

Development of a live app, integrated ijkplayer success, even if the completion of the live function half of the project, as long as there is a pull stream URL, you can play live

This article is mainly about the live app, need to use a very important open source framework ijkplayer , and then integration of this framework may be most 初学者 or more difficult, so this article mainly teaches you 解决集成【ijkplayer】遇见的各种坑 .

Many articles, may explain is how to do, I pay more attention to explain to 为什么 do so, we have what do not understand, also can 多多提出来 .

If you like my article, you can follow my Weibo: 袁峥 Seemygo, can also come to 袁峥 Seemygo, learn about our iOS training courses. Follow up will also update more content, have any question, welcome 简书留言 Zheng Acridine ...

Effect
Live. gif one, basic knowledge

README.md文件: A description of the framework that describes how the framework is used

编译语言: Before the program is executed, a special compilation process is required to compile the program into a machine language file, and the runtime does not need to be translated, so the program execution of the compiled language is highly efficient, such as oc,c,c++

解释性语言: Interpretive language programs do not need to be compiled, they are translated when the program is run, and each statement is executed. Such explanatory language needs to be translated one time at a time and is less efficient than once per execution.

解释性语言执行和编译语言执行的区别

    • The parsing of a line of explanatory language, if there is an error, will not execute, directly execute the next line.
    • Compiled language, as long as there are errors, you can not compile, a row can not be executed.

脚本语言: Belongs to the parsing language, it must be parsed by the interpreter, and its strips are translated into machine-readable instructions and executed in sequence.

    • Python: scripting language, suitable for Web application development, is conducive to development efficiency, now appears more and more powerful
    • PHP: Server-side scripting language for dynamic websites
    • JS: As the client's scripting language, in the browser to interpret the execution,
    • Shell: Operating system scripting language, commonly referred to as the command line used in Unix/linux
    • The compiled language, the execution file is binary. The scripting language is interpreted as execution, and the execution file is text

shell解释器: The shell is a command-line interpreter, the equivalent of Windows CMD, between the kernel and the user, responsible for passing the user's instructions to the kernel and echoing the execution results back to the user.

    • The default Unix has Shell,os Unix-based, so the OS comes with a shell.

bash: Bash is a shell interpreter version, with many versions of the shell, like people, and people of different countries.

    • Cow programmers see the bad shell interpreter, will write their own, slowly formed a number of standards, commonly used shell interpreter has such a few, SH, bash, CSH, etc.

shell: The shell that we usually refer to is the Shell scripting language, not the shell interpreter.

    • When writing the shell, the first line must indicate which shell interpreter the system needs to interpret your shell script, such as: #! /bin/bash, using Bash to parse the scripting language
    • 什么时候使用shell命令, for example, some system commands often need to be used, you can encapsulate the command into a script file, you will not have to knock it again, directly execute the scripting language.
    • For example Ijkplayer, download ffmpeg with a script file, because the download ffmpeg need to execute a lot of commands, all encapsulated in the script file.
    • When importing some third-party frameworks, it is often necessary to use a few commands, so it is generally encapsulated in a script file, and the commands that integrate the third-party framework are automatically executed as soon as the script is executed.

sh: Sheel script file suffix name

Second, download Ijkplayer
    • Go to station B to get to GitHub homepage, find Ijkplayer project, download source code Ijkplayer
    • Open demo, view usage,一般学习第三方库,都是先查看Demo

      Snip20160825_4.png
Third, compile the Ijkplayer step 1, find the Ijkplayermediademo and run
    • Tips‘libavformat/avformat.h‘ file not found

Bug1.png

原因: Because Libavformat is a library in FFmpeg and Ijkplayer is based on the FFmpeg library, you need to import ffmpeg

解决: View Ijkplayer's readme.md, which is generally explained.


Executes the script. png

init-ios.shRole of script: Download FFmpeg source code

    • To understand how the script is done, you can look at the previous article to take you into the script world, Ijkplayer's "init-ios.sh" script analysis, a comprehensive analysis of init-ios.sh what the script does.
How to Perform init-ios.shScript file
    • 步骤一:Locate the init-ios.sh script file

Locate init-ios.sh file. png
    • 步骤二:Open the terminal and CD into the Ijkplayer-master directory

Enter the init-ios.sh directory. png
    • Note that this is the CD folder

CD Ijkplayer-master.png
    • 步骤三:Enter./init-ios.sh and the current script is executed.

Executive Init-ios.sh.png
    • When you finish executing the script, you'll see that there's a ijkplayer ffmpeg

After executing the script. png2, download good ffmpeg source code, run demo again
    • Find or report a ‘libavformat/avformat.h‘ file not found mistake
    • 原因: Execute init-ios.sh, 仅仅是下载源码 but the source code does not participate in compiling, need to compile the source code into. A file
      • Demo relies on Ijkmediaplayer library

Demo source. png
    • Open the Ijkmediaplayer library and view the source code

Ijkmediaplayer project location. png
    • Open the Ijkmediaplayer Library


      Ijkmediaplayer source. png
    • Right-click to find that the library in FFmpeg is red, indicating that there is no


      Snip20160829_23.png
    • 解决: View Ijkplayer's readme.md


Compiling ffmpeg.png compiling FFmpeg library
    • Step one: Go to 脚本文件 the directory

      CD Ios.png
    • Step Two: Execute./compile-ffmpeg.sh clean
      • Step Two function: delete some files and folders, prepare for compiling ffmpeg.sh, when compiling ffmpeg.sh, will automatically create the files just deleted, in order to avoid file name conflict, so before compiling ffmpeg.sh, delete the folder or file that will be created automatically.

Snip20160828_19.png
    • Step three: Execute./compile-ffmpeg.sh all, really compiles the FFmpeg libraries for each platform, and generates a common library for the platform.

Executes the./compile-ffmpeg.sh all execution compile-ffmpeg.sh all before
After you compile the. png execution compile-ffmpeg.sh All
After compiling. Png3. Run the demo again, it will be successful because the Ijkmediaplayer library gets to the FFmpeg library.
    • After compiling the ffmpeg, the Ijkmediaplayer library displays


      Successfully obtained the FFmpeg library. png
    • Cmd+r,demo running successfully


The demo runs successfully. PNG Iv. how to integrate into Ijkplayer into your own project
    • Note: ijkplayer the README method in the more troublesome, inconvenient to carry, not recommended.

Snip20160830_9.png1. Recommend that you pack the Ijkmediaplayer into a static library and import it into your own project.
    • How to package, please refer to, iOS integrated Ijkplayer video Live frame, write very good, not a detailed introduction, but 只有发布版本的库 .
    • I packed myself. Ijkplayer Two repositories for debug and release (Debug and release), click to download
    • Because the file is too large to upload GitHub, it was uploaded to the Baidu cloud
2. Drag the Ijkplayer library directly into its own project,
    • To debug, drag into the debug version of the Ijkplayer library, publish it, and drag it into the release version of the Ijkplayer library.

Snip20160829_5.png3. Import Ijkplayer-dependent libraries to see Ijkplayer's Readme
Snip20160829_6.png
Snip20160829_7.png Five, using Ijkplayer Live 1.ijkplayer usage profile
    • Ijkplayer usage is relatively simple, in fact, as long as there is a live address, you can live
    • Note: The best 真机测试 , simulator test 比较卡,不流畅 , the real machine is no problem
2. Fetching data
    • Grabbed a lot of live app data, found that the quality of the presenter is the highest.
    • Url:http://116.211.167.106/api/live/aggregation?uid=133825214&interest=1 Anchor
      • uid= Account ID, here is my account ID
      • interest= interest, 1 means only view girls, haha
      • Up and down refresh interface not caught, just a moment to load 200 data, haha
- (void) loaddata{Map Guest Data URLNSString *urlstr =@ "Http://116.211.167.106/api/live/aggregation?uid=133825214&interest=1";Request data Afhttpsessionmanager *mgr = [Afhttpsessionmanager manager]; 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 = [Yzliveitem mj_objectarraywithkeyvaluesarray:responseobject[@ " Lives "]; [_tableview Reloaddata]; } failure:^ (nsurlsessiondatatask * _nullable task, nserror * _nonnull error) { NSLog (@ "%@", error);}] ;}
3. Get the Pull stream URL, live
    • IJKFFMoviePlayerController: The class used to do the live broadcast
- (void) Viewdidload {[Super Viewdidload];Self. View. backgroundcolor = [Uicolor Whitecolor];Set up a live placeholder imageNsurl *imageurl = [Nsurl urlwithstring:[NSString stringWithFormat:@ "http://img.meelive.cn/%@", _live. Creator. Portrait]]; [Self. ImageView Sd_setimagewithurl:imageurl Placeholderimage:nil]; //pull stream address nsurl *url = [NSURL Urlwithstring:_live.stream_addr]; //Create Ijkffmovieplayercontroller: Dedicated to live, incoming pull-stream address just fine ijkffmovieplayercontroller *playerVc = [[Ijkffmovieplayercontroller alloc] initwithcontenturl:url withoptions:nil]; //ready to play [PLAYERVC Preparetoplay]; //strong reference, anyway destroyed _player = PLAYERVC; Playervc.view.frame = [uiscreen mainscreen].bounds; [self.view INSERTSUBVIEW:PLAYERVC .view atindex:1];}        
4. End Playback
    • The interface does not play, be sure to remember to end the playback, otherwise it will report memory overflow

Memory Bug.png
- (void)viewWillDisappear:(BOOL)animated{    [super viewWillDisappear:animated];    // 界面消失,一定要记得停止播放    [_player pause];    [_player stop];}
Conclusion

Follow up will also update more information about the live broadcast, hope to do the church every friend from scratch to do a live app, and the demo will be gradually perfected.
Demo Click to download

    • Because the FFmpeg cubby is larger, about 100M.
    • Originally wanted to upload all the code, uploaded 1 hours, has not succeeded, gave up.
    • Provide another option that requires you to import the Ijkplayer library in detail:
    • After downloading the demo, open the Yzliveapp.xcworkspace problem

Open Yzliveapp.xcworkspace problem
    • Pod Install will solve

Snip20160830_12.png
    • Download Jkplayer Library, click to download
    • Drag the jkplayer directly into the same directory as the classes, run the program directly, you can succeed.

Drag into the Ijkplayer to the same level directory as classes. png
    • Note that you do not need to 打开工程,把jkplayer拖入到工程中 , but directly copy the Jkplayer library to the same level as the classes directory.
    • Error Demonstration:不要向下面这样操作

Snip20160830_14.png



Wen/袁峥 Seemygo (Jane book author)
Original link: http://www.jianshu.com/p/7b2f1df74420
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

"How to quickly develop a complete iOS Live App" (play article)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.