0

Im using this code to play a commercial video in my iOS application:

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {

UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
[videoView loadHTMLString:[NSString stringWithFormat:@"<iframe width=\"%f\" height=\"%f\" src=%@ frameborder=\"1\" allowfullscreen></iframe>",frame.size.width-10,frame.size.height-10,urlString] baseURL:nil];
[self.view addSubview:videoView];
[videoView release];
}

I want to force the user to see the video and close the UIWebView once the video is completed without allowing the user to shut the video off.

I think if i can make the Video plays automatically and set the:

videoView.userInteractionEnabled = NO;

that will force the user to watch it.

My Questions:

1- How to force the UIWebView using <iframe> ?

2- How to detect if the video finished playing?

3- Is there any other way (Better One) to play YouTube videos in iOS?

Glad to hear any other ideas or answers, Thanks in advance.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mutawe
  • 6,464
  • 3
  • 47
  • 90
  • You can detect if the video is finished with JavaScript and the [YouTube Player API](https://developers.google.com/youtube/iframe_api_reference). – Marcus Adams May 16 '13 at 13:09
  • 1
    Check this SO answer http://stackoverflow.com/a/14702453/2315974. But forcing the user to watch something is not a good idea and it's a bad practice. – danypata May 16 '13 at 13:12
  • Don't be surprised when you read 1-star reviews. – akashivskyy May 16 '13 at 13:13
  • @danypata can u explain why its a bad practice? Thanks in advance. – Mutawe May 16 '13 at 13:15
  • @danypata at least i want to play it automatically and close it when its done – Mutawe May 16 '13 at 13:19
  • 4
    There is no user in the world who want to be forced to do something in to an app, you should provide informations/functionality/data/etc through your app and let the user to decide if he/she wants to view or use what your app provides. If a user want's to watch your youtube video he/she will watch it, if not he/she will close the app and probably will never use it again. If this is your target for the app, you are on the right way to accomplish it, if not, it's better to let the user close the vide if he/she don't want to watch it. – danypata May 16 '13 at 13:19
  • Thank you @danypata, i will consider this at my app, at least i want to play it automatically and close it when its done,,, any idea?? – Mutawe May 16 '13 at 13:37
  • Did you check the SO answer posted in the above comment ? – danypata May 16 '13 at 13:47
  • Yes i did, that solve the finishing of the video, but has no auto play feature, BTW i tried that code before – Mutawe May 16 '13 at 13:49

2 Answers2

1

try this:

videoView.userInteractionEnabled = NO;

and you can create a UIButton to close the video.

M.Alatrash
  • 1,270
  • 1
  • 12
  • 30
-1

you can use LBYoutube for youtube videos. see following link

LBYouTube

SAMIR RATHOD
  • 3,512
  • 1
  • 20
  • 45
  • 1
    This example has nothing i asked for, no auto play, can't detect if the video finished playing !! – Mutawe May 16 '13 at 13:35