What is the best practice for uploading a video file?

I want to add a background view with a video (or gif), as in the Uber application. I would like to use video files for a long time in my application.

And I want to know the answers to these questions:

  • Which of them will consume less battery power.
  • Can I use it on iPhone or iPad.
  • Executing this method

Screen capture of registration form

enter image description here

+6
source share
6 answers

Primarily,

you have two main options: use imageView with GIF or using video for background using AVPlayer or MPMoviePlayerController . You can find many examples for both ways, here are a few:

Answering your questions:

Which of them will consume less battery power

The video is usually used: as noted by the user, the vikingosegundo video is usually optimized, and their codecs deal with GPUs; GIF mapping should be the only "CPU-job" because it just shows a frame loop. Thus, energy comparison occurs between a simple frame cycle (GIF) and a more complex frame cycle, which can be accelerated in many ways (video). However, in my experience a small GIF gives good performance.

Can i use it on iPhone or iPad

In both cases, you must be careful about the aspect ratio and auto-detection restrictions.

Executing this method

Great in both cases, but you have to be careful about the size of your GIF or video: the larger your file (GIF or video), the performance should be worse. For a video more precisely, a higher quality worse should be performance, while the duration of the video should not affect.

+7
source

One of the popular and open source library for downloading the source code of the source video files from the link below

Let it help.

+4
source

You can use many open source components for this purpose.

For example, this one supports GIF, movie playback

https://github.com/kaiinui/KIChameleonView

Or is it for GIF playback

https://github.com/liyong03/YLGIFImage

0
source

You can directly use the video and play it in repeat mode,

OR

You can use images in conjunction with the standard animationImages property of the UIImageView class.

As below

  YourImageView.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"sample_1.png"], [UIImage imageNamed:@"sample_2.png"], [UIImage imageNamed:@"sample_3.png"], [UIImage imageNamed:@"sample_4.png"], [UIImage imageNamed:@"sample_5.png"], nil]; // How many seconds it should take to go through all images one time. YourImageView.animationDuration = 5.0; // How many times to repeat the animation (0 for indefinitely). YourImageView.animationRepeatCount = 4; [YourImageView startAnimating]; 

Hope this helps you.

0
source

This can be done using a set of images in .png or .jpeg format and assign the images << 22>:

 UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 548)]; //Add images which will be used for the animation using an array. Here I have created an array on the fly NSMutableArray *drawingImgs = [NSMutableArray array]; [drawingImgs addObject:[UIImage imageNamed:@"image1.png"]]; [drawingImgs addObject:[UIImage imageNamed:@"image2.png"]]; [drawingImgs addObject:[UIImage imageNamed:@"image3.png"]]; [drawingImgs addObject:[UIImage imageNamed:@"image4.png"]]; [drawingImgs addObject:[UIImage imageNamed:@"image5.png"]]; backgroundImageView.animationImages = drawingImgs; //Set the duration of the entire animation backgroundImageView.animationDuration = 0.5; //Set the repeat count. If you don't set that value, by default will be a loop (infinite) backgroundImageView.animationRepeatCount = 1; //Start the animationrepeatcount [backgroundImageView startAnimating]; 
0
source

I used xCode 7 and iOS 9. I used a gif image and it works correctly.

  NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Name of your image" ofType:@"gif"]; NSData *gif = [NSData dataWithContentsOfFile:filePath]; UIWebView *webViewBG = [[UIWebView alloc] initWithFrame:self.view.frame]; [webViewBG loadData:gif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil]; webViewBG.userInteractionEnabled = NO; [self.view addSubview:webViewBG]; 
0
source

Source: https://habr.com/ru/post/989510/


All Articles