Simple frame Demo for image and video playback

Source: Internet
Author: User

Simple frame Demo for image and video playback

Recently, I found some basic knowledge about my own shortcomings. I accidentally saw my own code open-source as a great God in the same industry in a QQ group. In addition, he showed off and asked us to find a Bug. So he looked at it out of curiosity and opened a Demo about image and video playback. That is, the Demo I will talk about next.

The reason for writing this Demo is that the recent project involves this knowledge. No matter what the reason is, there is always no error in learning more. The following describes the functions of this Demo.

Function:

Supported statuses:

1. images have been published (Network Image Browsing and flow layout)

2. The image is not released (Local Image Upload, release, and preview)

3. Video Playback

Supported la s:

  Flow Layout,Linear Layout

Supported gestures:

  Click,Double-click,Kneading,Rotate,Drag,Slide

Where can I use this framework:

It is mainly used for social apps to present a group of images or play some standard MP4 files.

Third-party frameworks dependent on:

  • Image Browsing dependency framework
    • MBProgressHUD
    • SDWebImage
  • Video Playback dependency framework
    • HttpServer
Main PYPhotosView frameworks
@ Interface PYPhotosView: UIScrollView/** proxy */@ property (nonatomic, weak) id <PYPhotosViewDelegate> delegate;/** network image album */@ property (nonatomic, strong) NSArray * photos;/** local album Image array (up to nine images by default. When the input image array contains more than nine images, take the first nine images) */@ property (nonatomic, strong) NSMutableArray * images;/** video link (video from the network) **/@ property (nonatomic, copy) NSString * movieNetworkUrl; /** local video address (with file type suffix) */@ property (nonatomic, copy) NSString * m OvieLocalUrl;/** status of all images (released by default) */@ property (nonatomic, assign) PYPhotosViewState photosState;/** Image Layout (flow layout by default) * // @ property (nonatomic, assign) PYPhotosViewLayoutType layoutType;/** the image paging indicator type (pageControll by default. When there are more than nine images, change to label.) */@ property (nonatomic, assign) PYPhotosViewPageType pageType;/** image spacing (5 by default) */@ property (nonatomic, assign) CGFloat photoMargin;/** image width (70 by default) */@ property (nonatomic, assign) CGFloat photoWidth;/** Image Height (70 by default) */@ property (nonatomic, assign) CGFloat photoHeight;/** maximum number of lines (3 by default). When the Image Layout is linear, this setting is invalid */@ property (nonatomic, assign) NSInteger photosMaxCol;/** maximum number of uploaded images before uploading. The default value is 9 */@ property (nonatomic, assign) NSInteger imagesMaxCountWhenWillCompose;/** quickly create a photosView object */+ (instancetype) photosView;/** photos: array for saving image links */+ (instancetype) photosViewWithPhotos :( NSArray *) photos;/** images: array for storing local images */+ (instancetype) photosViewWithImages :( NSMutableArray *) images;/*** photos: array for saving image links * type: layout type (flow layout by default) */+ (instancetype) photosView :( NSArray *) photos layoutType :( PYPhotosViewLayoutType) type;/*** photos: array for saving image links * maxCol: maximum number of images displayed per line */+ (instancetype) photosView :( NSArray *) photos photosMaxCol :( NSInteger) maxCol; /** automatically calculates the size of PYPhontosView based on the number of images and image status */-(CGSize) sizeWithPhotoCount :( NSInteger) count photosState :( NSInteger) state; /*** refresh the image (not released) * images: New Image array */-(void) reloadDataWithImages :( NSMutableArray *) images; @ end
How to Use PYPhotosView
  • Use Cocoapods:
    • pod "PYPhotosView"
    • Import the main header file#import <PYPhotosView.h>
  • Manual import:

    • SetPYPhotosViewAll files in the folder are merged into the project.
    • Import the main header file#import "PYPhotosView.h"
    • Note:If the project has a dependency on a third-party framework:MBProgressHUD (for Image Browsing and publishing), SDWebImage (for Image Browsing and publishing), HttpServer (for video playing and caching).DependencyFolder, the framework that does not exist in the project is merged into the project.

    Note:

    You mustAppDelegate.mImportHTTPServer.h,DDLog.h,DDTTYLogger.hHeader file and implement the following methods (for more information, see PYPhotosViewExample'sAppDelegate.m) File

    -(Void) startServer {// Start the server (and check for problems) NSError * error; if ([httpServer start: & error]) {NSLog (@ "Started HTTP Server on port % hu", [httpServer listeningPort]);} else {NSLog (@ "Error starting HTTP Server: % @", error) ;}} // call after the program is started-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {[DDLog addLogger: [DDTTYLogger sharedInstanc E]; // create a local server httpServer = [[HTTPServer alloc] init]; // set the communication type to tcp [httpServer setType: @ "_ http. _ tcp. "]; // set the port [httpServer setPort: 12345]; // Serve files from our embedded Web folderNSString * webPath = [NSHomeDirectory () stringByAppendingPathComponent: @ "Library/Caches/PYPhotosView/Temp"]; NSFileManager * fileManager = [NSFileManager defaultManager]; if (! [FileManager fileExistsAtPath: webPath]) {[fileManager createDirectoryAtPath: webPath withIntermediateDirectories: YES attributes: nil error: nil];} [httpServer setDocumentRoot: webPath]; [self startServer]; return YES;} // call when the program enters the background for running-(void) applicationDidEnterBackground :( UIApplication *) application {[httpServer stop];} // call the program back to the foreground when running-(void) applicationWillEnterForeground :( UIApplication *) application {[self startServer];}
For more information, see PYPhotosViewExample)
  • Published (Web Image Browsing)

    Sample Code:

// 1.1 create an image link array NSMutableArray * imageUrls = [NSMutableArray array]; for (int I = 0; I <9; I ++) {// 1.2 image link NSString * imageUrl = [NSString stringWithFormat: @ "https://github.com/iphone5solo/learngit/raw/master/imagesForPhotosView/image%02d.jpg", I + 1]; // 1.3 add image link [imageUrls addObject: imageUrl];} // 2. create a photosView PYPhotosView * photosView = [PYPhotosView photosViewWithPhotos: imageUrls]; // 3. add photosView [self. view addSubview: photosView];
  • Unpublished (Local Image Upload, release, and preview)

    Sample Code:

// 1. create a Local Image array NSMutableArray * imagesM = [NSMutableArray array]; for (int I = 0; I <arc4random_uniform (4) + 1; I ++) {[imagesM addObject: [UIImage imageNamed: [NSString stringWithFormat: @ "% 02d", I + 1];} // 2.1 set local image PYPhotosView * photosView = [PYPhotosView photosViewWithImages: imagesM]; // 3. sets the proxy photosView. delegate = self; // 4. add photosView [self. view addSubview: photosView];
  • Video Playback

    Sample Code

// 1. create photosView PYPhotosView * moviePhotosView = [PYPhotosView photosView]; // 2. sets the network link of the video moviePhotosView. movieNetworkUrl = @ "http://static.tripbe.com/videofiles/20121214/9533522808.f4v.mp4"; // 3. add photosView [self. view addSubview: moviePhotosView];
Custom photosView can be modified by setting the object property value of photosView.
  • Set the layout type (default: streamline layout)
// Set the layout to linear layout. photosView. layoutType = PYPhotosViewLayoutTypeLine;
  • Set the pagination indicator type (pageControll indicator by default)
// Set the indicator type to Text indicator photosView. pageType = PYPhotosViewPageTypeLabel;
  • Set the image spacing (5 by default)
// Set the image spacing to 10photosView. photoMargin = 10;
  • Set the image size (70*70 by default)
// Set the image width (width) photosView. photoWidth = 100; // set the Image height (height) photosView. photoHeight = 60;
  • Set the maximum number of images per line (3 by default)
// Set the maximum number of columns for an image. photosView. photosMaxCol = 6;
  • Set the maximum number of images uploaded before uploading (9 by default)
photosView.imagesMaxCountWhenWillCompose = 15;

  

 

This Demo can greatly reduce the workload, but you must understand its principles before using it. Code Source: http://www.cnblogs.com/mobile-development/p/5720835.html

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.