Play icon in a button - youtube

How do I get this play arrow in a button? This arrow should look like if you have an website with an embed YouTube video.
(source: iPhoneIncubator.com)

If you're going to be playing YouTube content directly from the app there is some information on how to place a UIWebView to display the content from YouTube. Check out Method #2 which demonstrates the creation of this thumbnail.
YouTube API Information
For other video sources, you could set the background color of the button to be a still frame of the video using
button.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: #"videoStill.png"]];
Then set the button's image property to a play button with transparency.
[button setImage:[UIImage imageNamed:#"playButton.png"] forState:UIControlStateNormal];

Related

How to display animation on login screen

I have a basic login screen setup; logo, username, and password field. I had a designer make a cool animation for the logo and received it as an MP4 file.
I would like to make it so that when the user opens the app, or visits the login screen, the logo animation plays once in my view.
I was only able to find libraries to play MP4 files full screen or with a play button being triggered on the middle of the view with a close button on the top corners, similar to how you would watch a regular video on iPhone.
Anyone know how to play an embedded animation within a view just once? I could possibly ask for the animation in a different file format if theres another way.
Thanks!
I think you can achieve this using .gif file in a better way.
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [[NSBundle mainBundle] URLForResource:#"test" withExtension:#"gif"];
UIImage *testImage = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
self.dataImageView.animationImages = testImage.images;
self.dataImageView.animationDuration = testImage.duration;
self.dataImageView.animationRepeatCount = 1;
self.dataImageView.image = testImage.images.lastObject;
[self.dataImageView startAnimating];
}
.gif file would play for only once & then last frame of that file would be stable.
Hope this would help..!!!
You can use MPMoviePlayerController to play the movie.
Refer to this post
iPhone SDK:How do you play video inside a view? Rather than fullscreen

Custom remote event handling in app from iOS lock screen

How does spotify handle custom remote events? Currently on iPhone 6 running iOS 8.1.3 and spotify version 2.4.0.1822 I get the following controls on the lock screen when I turn on spotify radio. Ive tried reading all docs pertaining to remote events, and I'm unable to find any resources which allow custom remote events from the lock screen.
Maybe that is implemented with MPRemoteCommandCenter.
Here is example...
MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter];
[[remoteCommandCenter skipForwardCommand] addTarget:self action:#selector(skipForward)];
[[remoteCommandCenter togglePlayPauseCommand] addTarget:self action:#selector(togglePlayPause)];
[[remoteCommandCenter pauseCommand] addTarget:self action:#selector(pause)];
[[remoteCommandCenter likeCommand] addTarget:self action:#selector(like)];
Implement this code, play music on your app, and lock your iPhone. You will probably see a customized lock screen.
Note - Menu can be customized label, but it can not customize icon image and number of row.

How to play YouTube video in iOS not in fullscreen?

I've been trying to get YouTube music videos to play in my iOS app in a small window (not full screen) and can't get it to work. I've tried the following:
I first used the YouTube API and created a YTPlayerView as instructed here: https://developers.google.com/youtube/v3/guides/ios_youtube_helper#adding_ytplayerview. This allowed me to play videos in-line, but many videos were unable to be played because of licensing issues, stating "This video contains content from *. It is restricted from playback on certain sites."
I then tried using a UIWebView, which successfully played the music videos that were previously unavailable. However, these videos were always forced to play in fullscreen mode, even when I set webView.allowsInlineMediaPlayback = YES;
I also tried embedding the video using the technique discussed here: How to embed YouTube video on iOs and play it directly on UIWebview without full screen. This worked to keep videos inline, but again, rendered certain videos unplayable.
I finally tried using an MPMoviePlayerController, but later found out that it can't actually play YouTube videos, as we don't have access to the direct links of video files, so this was another no-go.
Apps like PingTune were clearly able to figure this out using YouTube - they are able to play YouTube music videos in a custom, non-fullscreen view and without ads - what am I missing? Is there a part of the YouTube API that allows me to play these music videos that I implemented incorrectly?
I've never tried it myself but you could try LBYouTubeView by Laurin Brandner. LBYouTubeView is just a small view that is able to display YouTube videos in a MPMoviePlayerController. You even have the choice between high-quality and standard quality stream.
Code sample
LBYouTubePlayerViewController* controller = [[LBYouTubePlayerViewController alloc] initWithYouTubeURL:[NSURL URLWithString:#"http://www.youtube.com/watch?v=1fTIhC1WSew&list=FLEYfH4kbq85W_CiOTuSjf8w&feature=mh_lolz"] quality:LBYouTubeVideoQualityLarge];
controller.delegate = self;
controller.view.frame = CGRectMake(0.0f, 0.0f, 200.0f, 200.0f);
controller.view.center = self.view.center;
[self.view addSubview:self.controller.view];

Rotated MPMoviePlayerController is missing controls

I need to rotate my MPMoviePlayerController and am doing so as follows:
self.player = [[MPMoviePlayerController alloc] initWithContentURL:selectedImageURL];
[self.player.view setFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
self.player.controlStyle = MPMovieControlStyleEmbedded;
self.player.view.transform = CGAffineTransformMakeRotation(M_PI_2*3);
self.player.view.center = self.view.center;
[self.view addSubview:self.player.view];
[self.player play];
With the rotated video, though, I don't see the controls.
How do I ensure that the controls are in view?
Also, as a related question, is there a way to specify the placement of the controls? I'd like the controls to appear on the bottom of the screen for portrait videos and on the right of the screen for landscape videos.
Test Video
You can try out the code with this video: https://dl.dropboxusercontent.com/u/1000620/lego_test.mp4
I think video playing and processing should be handled separately. In fact, I think MPMoviePlayerController is only capable of playing video. (Am I wrong?)
Video playing:
Customized control should includes some steps as follow:
1) set controlStyle=MPMovieControlStyleNone;
2) add a overlay view to containerView, place your controls on this view;
3) make MPMoviePlayerController handling controls events.
Example "MoviePlayer" shows how to add overlay view to MPMoviePlayerController.
if you just want to rotate video playing in fullscreen, the following link will be help
MPMoviePlayerController fullscreen in landscape mode in a portrait project
Video processing is another thing. Maybe you need reading Example "AVSimpleEditoriOS".
By using AVFoundation framework, you can reading frames from video, processing (rotate, zoom), writing to displaying buffer in real time.

How to have video as a background in iOS?

I'm finding it difficult to search for this, background video searches for iOS typically refer to multitasking and switching apps with video.
I want to know if it's possible to have a video playing full screen without movie player controls, while displaying another view on top of that with logo, buttons, text, etc...
So,
Background: 15 second video loop -
Foreground: login / signup buttons, logo, etc...
There are a number of options, but the simplest will be to use a MPMoviePlayerController, with its repeatMode property set to loop forever, and its controlStyle set to none. That will give you a view with a looped movie with no controls that you can use as a background by adding it to your view hierarchy.
OP here - I was able to display a video full screen using this code (in viewDidLoad):
(don't forget to substantiate player as a property with MPMoviePlayerController *player;)
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"videoname" ofType:#"m4v"]]];
[player.view setFrame: self.view.bounds];
player.repeatMode = MPMovieRepeatModeOne;
player.controlStyle = MPMovieControlStyleNone;
[myView addSubview:player.view];
[player play];
And that worked fine - it displays a video fullscreen without video controls. What I had a problem with was displaying buttons and graphics above that. Even though my view hierarchy had the player.view seemingly behind my view with buttons, I couldn't get the buttons to appear.
I fixed that by adding in:
[player.view addSubview:overlayView];
Just set the layer you intend to display above the video to an IBOutlet and then use the video view to add that view (overlayView in this case) as a subview.
I actually prefer a way that is portrayed in this tutorial
basically the idea is to create a gif of your video, crop it to iPhone Screen size and load it into an un-interactive UIWebView. I believe this will get the job done if you don't need any audio, and it's basically done effortlessly.
I hope it helps you =)

Resources