How can I overlap videos in my iPhone app? [closed] - iphone

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm looking to make an iPhone app that plays videos that can overlap. Like this:
How might I do this?

Use UICollectionView
1) Inefficient way : If you want to play all media simultaneously.
Grid View of mediaplayers.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CollectionCell forIndexPath:indexPath];
// get URL
Player *mediaPlayer = [[self playerArray]objectAtIndex:indexPath.row];
NSURL* videoURL = [NSURL URLWithString:mediaPlayer.url];
MPMoviePlayerController* mPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[mPlayer prepareToPlay];
[mPlayer play];
//For viewing partially.....
[mPlayer.view setFrame:CGRectMake(/*Your frame*/)];
[mPlayer.view.backgroundColor = [UIColor grayColor];
[cell addSubview:mPlayer.view];
return cell;
}
2) Efficient way: Place the grid with thumbnails and replace media player object with UIImageview when user taps on a cell (in this case place the above code in didSelectRow )

Related

Trying to instantiate a UIView through class method [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm experimenting with different ways of displaying a UIView on the screen... I currently have this code, and think it should work to add a green UIView to the app's window, however, it doesn't:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(#"init");
self.backgroundColor = [UIColor greenColor];
self.alpha = 1;
}
return self;
}
+ (SMLoginView *)sharedView{
static dispatch_once_t onceToken;
static SMLoginView *sharedView;
dispatch_once(&onceToken, ^{
sharedView = [[self alloc]initWithFrame:[UIScreen mainScreen].bounds];
});
return sharedView;
}
+ (void)showLoginView{
[[self sharedView]show];
}
- (void)show{
NSLog(#"Show");
[[[[UIApplication sharedApplication] delegate] window] addSubview:self];
}
Insted, u can add it in the called method, because u are adding it in the shared class itself, thats wy it did't appeared.
try this
suppose u are calling this shared method in this "ViewController.m" class
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
SMLoginView *sharedView = [SMLoginView sharedView]; //you always get a shared view handle that view in this class
[self.view addSubview:sharedView]; //add the shared view hear not in the shared class.
}
hope u got this :)

Embed youtube video and autoplay on iOS 6 don't work [duplicate]

This question already has answers here:
Can you autoplay HTML5 videos on the iPad?
(7 answers)
Closed 9 years ago.
I'm trying to embed youtube video and autoplay it on my app. The code is not working on iOS6, however it runs on older iOS 5 perfectly.
I do it in this way:
-(IBAction)playVideo:(id)sender {
myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
myWebView.delegate = self;
[myWebView setAllowsInlineMediaPlayback:YES];
myWebView.mediaPlaybackRequiresUserAction=NO;
[myWebView loadHTMLString:[NSString stringWithFormat:#"<embed id=\"yt\" src=\"%#\" type=\"application/x-shockwave-flash\" width=\"300\" height=\"300\"></embed>", #"http://www.youtube.com/watch?v=TbsXUJITa40"] baseURL:nil];
}
- (UIButton *)findButtonInView:(UIView *)view {
UIButton *button = nil;
if ([view isMemberOfClass:[UIButton class]]) {
return (UIButton *)view;
}
if (view.subviews && [view.subviews count] > 0) {
for (UIView *subview in view.subviews) {
button = [self findButtonInView:subview];
if (button) return button;
}
}
return button;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
UIButton *b = [self findButtonInView:webView];
[b sendActionsForControlEvents:UIControlEventTouchUpInside];
}
So- when the webview is loaded, it finds automatically the uibutton and the video starts. I can't understand, why in iOS 6 this method doesn't work anymore. It loads the video, but nothing appears...
Anyone can help me? I'm going crazy to try to solve it...
You need to use JS command. This link should help.
I hope it's not too late for an answer, but it plain simply is not possible in iOS. Like Apple states on it's documentation: https://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/AudioandVideoTagBasics/AudioandVideoTagBasics.html
To prevent unsolicited downloads over cellular networks at the user’s expense, embedded media cannot be played automatically in Safari on iOS—the user always initiates playback. A controller is automatically supplied on iPhone or iPod touch once playback in initiated, but for iPad you must either set the controls attribute or provide a controller using JavaScript.
Please pay attention that the documentation linked above is for Safari in general, not iOS-specific. To me, this was confusing on the first read until I noticed that.
So unfortunately no, for the moment this will not work on iOS.

Will Apple accept a custom UIAlert? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
I just read the iOS Human Interface Guidelines. In the chapter about Alerts, Action Sheets, and Modal Views (see here), I found this line :
The background appearance of an alert
is system-defined and cannot be
changed.
In my app I created my own UICustomAlert, inheriting from the UIAlertView class, whith following methods :
- (id)initWithImage:(UIImage *)image andButton:(UIButton *)button
{
if (self == [super init])
{
self.backgroundImage = image;
self.bigButton = button;
}
return self;
}
- (void)drawRect:(CGRect)rect
{
CGSize imageSize = self.backgroundImage.size;
[self.backgroundImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
[self addSubview:bigButton];
}
- (void) show
{
[super show];
CGSize imageSize = self.backgroundImage.size;
self.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height);
}
- (void)didAddSubview:(UIView *)subview
{
if ([subview isMemberOfClass:[UIImageView class]])
[subview removeFromSuperview];
}
I create my UICustomAlert this way :
UIAlertView *alert = [[UICustomAlert alloc] initWithImage:backgroundImage andButton:bigButton];
[alert show];
It permits me to show a UIAlert with a transparent background, and only one image (the backgroundImage).
But knowing what is written in iOS HIG, do you think Apple will reject the app ?
Thanks.
My gut feeling is that you're probably safe. There's nothing stopping you from implementing something like that from scratch. However I have had an app rejected for not following the HIG (they didn't like the way I worded an error message), so they are more than just "guidelines".

How to play videos from youtube, metacafe etc in a native iphone app?

I get a feed which consists of a URL pointing to the videos from sites like youtube, metacafe etc.
I found this post suggesting how to use UIWebView to load the video into the app. However I don't want the video to play in full screen mode. I want it to play in the frame I have allocated for it.
How do I make the youtube video which is loaded by embedding html into the uiwebview play in the frame allocated to it and not in full screen mode?
How do we play videos from sites like metacafe and comedy central and other sites where url doesn't point to a file but instead loads a player if pasted on browser.
Are there any applications which have achieved to play the same as a native iphone app?
Any help in this regards would be greatly helpful.
EDIT:
I want to know how do we play a video from the url say - http://www.dailymotion.com/swf/video/xe1l96
I would like to know how to play the video in the webview itself. I want to use the space around it to display other information. Currently it forces full screen mode.
Safari is able to play dailymotion and vimeo videos by lauching the quicktime player. So I would like to know how to redirect to play the videos using quicktime player.
How do I play videos from youtube and metacafec in a native iphone app?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UIWebView *wbView = (UIWebView *)[cell.contentView viewWithTag:1];
NSString *embedHTML = #"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%#\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML,url, 64.0, 64.0];
[wbView loadHTMLString:html baseURL:nil];
}
"url" is the youtube video url
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [category_table cellForRowAtIndexPath:indexPath];
UIWebView *wbView = (UIWebView *)[cell.contentView viewWithTag:1];
UIButton *btn = [self findButtonInView:wbView];
[btn sendActionsForControlEvents:UIControlEventTouchUpInside];
}
// detecting the play button on the you tube video thumbnail
- (UIButton *)findButtonInView:(UIView *)view {
UIButton *button = nil;
if ([view isMemberOfClass:[UIButton class]]) {
return (UIButton *)view;
}
if (view.subviews && [view.subviews count] > 0) {
for (UIView *subview in view.subviews) {
button = [self findButtonInView:subview];
if (button) return button;
}
}
return button;
}
- (void)webViewDidFinishLoad:(UIWebView *)_webView {
UIButton *button = [self findButtonInView:_webView];
[button sendActionsForControlEvents:UIControlEventTouchUpInside];
}
Basically, i had to show thumbnails in table cell
Praveen,
Your video will always play full screen on iPhone & iPod. The mentioned flag (allowsInlineMediaPlayback) only works on iPad...
YouTube is easy. Just set the UIWebView's allowsInlineMediaPlayback property to YES.
The other stuff is just a flash player that wraps around a video. It's going to be harder, and probably not worth it without the backing of the site in question.
Good luck, and if you need any more help just comment/edit your question.

placing a call programmatically on iPhone and return to the same app after hangup [duplicate]

This question already has answers here:
Make a phone call programmatically
(13 answers)
Closed 8 years ago.
I would lie to place a call in my app (I can use the tel:) but I would like to return to my app where I left after the users hangs up.
Is that possible?
I got this code from Apple site and it works perfectly:
-(IBAction) dialNumber:(id)sender{
NSString *aPhoneNo = [#"tel://" stringByAppendingString:[itsPhoneNoArray objectAtIndex:[sender tag]]] ; NSURL *url= [NSURL URLWithString:aPhoneNo];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
if ([osVersion floatValue] >= 3.1) {
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
webview.hidden = YES;
// Assume we are in a view controller and have access to self.view
[self.view addSubview:webview];
[webview release];
} else {
// On 3.0 and below, dial as usual
[[UIApplication sharedApplication] openURL: url];
}
}
No it's not. The user controls where they navigate after the phone call has ended I'm afraid. by default, it stays in the phone application, and the only way for the user to exit out of it is to hit the home button, which takes them to their main screen. Save your state, and reload it when they come back like everyone else.
You cannot return to the app automatically, after the call completes, but if your app supports iOS 4, its multitasking features (if the app supports them) can bring the user back to the spot where he or she left off before the call, when the app is relaunched.
If you use iOS 3 or earlier, you will need to manually save the app's state yourself and then bring the user back to that state on relaunch.