IOS Local video and network video stream playback

Source: Internet
Author: User
Tags uikit

Requirements: Recently the company needs to do a building intercom function: the door machine (connected to WiFi) dial to the indoor machine (corresponding WiFi) devices to call, the indoor machine receives the call will be received after the data UDP broadcast forwarding, the phone (connected to the WiFi) received video stream, Real-time display video data (mobile phone can answer, hang up, phone answering, the indoor machine does not show the video, just to forward. )

The simple point is that the mobile phone client needs to do a similar to the live platform software, real-time display of video, real-time playback of the received sound data, and real-time phone microphone received by the sound back to the indoor machine, indoor machine responsible for forwarding to the door machine.

Before I have ever done video playback is the direct playback of local files, has never done a network video streaming playback, Baidu is a lot of the introduction of how the framework is used, according to its process is not feasible, there is no detailed use of the process!!! Want to cry!!!

This article is about the local video file playback and network video playback and the use of the tripartite framework, there is no place to welcome correct!!!

#pragma mark-Local video file playback

Using Avfoundation.framework

First step: Import frame Avfoundation.framework

Tested: Do not import this frame can also play, in the third step when the use of the line, in order to avoid the unknown bug or obediently import it!!!

Step two: Drag a video file into your project

Step Three: Code implementation

#import "ViewController.h"#import<AVFoundation/AVFoundation.h>//need to import frames#defineeyscreenwidth [[UIScreen Mainscreen] Bounds].size.width#defineeyscreenheight [[UIScreen Mainscreen] Bounds].size.height@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //1. Get Test.mp4 's specific path from MainbundleNSString * Path = [[NSBundle mainbundle] Pathforresource:@"Test"OfType:@"mp4"]; //2. URL of the fileNsurl * url =[Nsurl Fileurlwithpath:path]; //3. Create the player based on the URL (the player itself cannot display the video)Avplayer * player =[Avplayer Playerwithurl:url]; //4. Create a view playing layer based on the playerAvplayerlayer * Layer =[Avplayerlayer Playerlayerwithplayer:player]; //5. Set the size of the layerLayer.frame = CGRectMake (0,0, Eyscreenwidth, eyscreenheight); //6. Add a layer above the view of the controller[Self.view.layer Addsublayer:layer]; //7. Start Playback[player play];}@end

#pragma mark--network video stream playback

Way One: Mobilevlckit.framework

First step: Download Mobilevlckit.framework

1. Can go to Baidu website address, the above has detailed compiling steps, GitHub above also has the detailed tutorial!!! Take the sixth step directly after--->!!!

2. I have compiled the real machine and the simulator can be used: mobilevlckit.framework

Link: https://pan.baidu.com/s/1o8hsgg6 Password: ZSWP If the connection fails, please email: [Email protected] or message below!!!

The second step: Download the downloaded zip decompression, Mobilevlckit folder in the Mobilevlckit.framework dragged into your project

Fourth step: Select Finish

Fifth step: Add dependent libraries

1:  AudioToolbox.framework

2:  VideoToolbox.framework

3:  CoreMedia.framework

4:  CoreVideo.framework

5:  CoreAudio.framework

6:  AVFoundation.framework

7:  MediaPlayer.framework

8:  libstdc++.6.0.9.tbd

9:  libiconv.2.tbd

10: libc++.1.tbd

11: libz.1.tbd

12: libbz2.1.0.tbd

A total of 12

After completion:

Sixth step: Using the framework

ViewController.h

#import <UIKit/UIKit.h>@interface  viewcontroller:uiviewcontroller// The path of the video stream, the address of the video stream coming over @property (nonatomic, copy) NSString * Rtsppath; @end

Viewcontroller.m

#import "ViewController.h"#import<MobileVLCKit/MobileVLCKit.h>//macro with wide screen height#defineeyscreenwidth [[UIScreen Mainscreen] Bounds].size.width#defineeyscreenheight [[UIScreen Mainscreen] Bounds].size.height@interfaceViewcontroller ()//Video Playback@property (nonatomic, strong) Vlcmediaplayer *player;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload];
//1. Create a playback view, the simulator test will be problematic!!! The real machine can play normallyUIView *videoview = [[UIView alloc] Initwithframe:cgrectmake (0,0, Eyscreenwidth, Eyscreenheight)]; [Self.view Addsubview:videoview]; //2. Create a playerSelf.player =[[Vlcmediaplayer alloc] initwithoptions:nil]; //3. Set Playback layerSelf.player.drawable =Videoview; //4. Set the playback pathSelf.player.media =[Vlcmedia Mediawithurl:[nsurl URLWithString:self.rtspPath]; //5. Start Playback[Self.player play];}- (void) dealloc{if(self.player.isPlaying) {[Self.player stop]; }}@end

Seventh step: real-machine testing

Command + R Run error

In the project setup, setting searches for Bitcode and modifies yes to No

If an error occurs, comment out the 38th line of the corresponding file.

Running Again is OK!!!

If you do not try to viewcontroller.m----->viewcontroller.mm

If the path above is a local path, the local video can be played!!!

Way two: Ijkmediaframework

First step: Download Ijkmediaframework

1. Can go to Baidu website address, the above has detailed compiling steps, GitHub above also has the detailed tutorial!!! And then proceed directly to the third step!!!

2. I have compiled the real machine and the simulator can be used: ijkmediaframework

Link: Https://pan.baidu.com/s/1dFGM9uL Password: gxi6 If the connection fails, please email: [Email protected] or message below!!!

The second step: Unzip the downloaded Ijk.zip, the Ijk folder

1, Ijkmediaframework.framework

2, LIBCRYPTO.A

3, Librtmp.a

4, LIBSSL.A

A total of 4 dragged into your project

Step Three: Write code

ViewController.h

#import <UIKit/UIKit.h>@interface  viewcontroller:uiviewcontroller// the path of the video stream @property (nonatomic, copy) NSString * Rtsppath; @end

Viewcontroller.m

#import "ViewController.h"#import<IJKMediaFramework/IJKMediaFramework.h>//macro Definition#defineeyscreenbounds [UIScreen mainscreen].bounds@interfaceViewcontroller () @property (nonatomic, strong) Ijkffmovieplayercontroller*Ijkplayer;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //initializing the playback controllerSelf.ijkplayer =[[Ijkffmovieplayercontroller alloc] InitWithContentURLString:self.rtspPath Withoptions:nil]; //set the print level and the test finds no effect[Ijkffmovieplayercontroller Setloglevel:k_ijk_log_debug]; //set the view size of the controllerSelf.ijkPlayer.view.frame =Eyscreenbounds; //The controller view is added to its own view[Self.view AddSubview:self.ijkPlayer.view];}- (void) Viewwillappear: (BOOL) animated{[Super viewwillappear:animated]; if(!self.ijkPlayer.isPlaying) {//Play[Self.ijkplayer Preparetoplay]; }}- (void) Viewwilldisappear: (BOOL) animated{[Super viewwilldisappear:animated]; if(self.ijkPlayer.isPlaying) {//Close[Self.ijkplayer shutdown]; }}@end

Note: The way one and two can only use one, because they will have a conflict, temporarily did not find the solution!!! (personal feeling should be in two ways. A) conflict with the system's. TBD

More Content-Blog navigation One piece of the week yo!!!

Have any questions about iOS development! Welcome to the message below!!! or email [email protected] Although I'm not sure I can answer it, I'll ask iOS developers!!! Answers to your questions!!!

IOS Local video and network video stream playback

Related 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.