add running videos in a scrollView - iphone

I have created a scrollView and need to add some running videos to it.
I did the following thing:
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scrollView.pagingEnabled = YES;
NSURL *fileUrl1 = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:#"AUDI_anti_crevaison_1" ofType:#"mp4"]];
NSURL *fileUrl2 = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:#"AUDI_Utilisation_de_la_roue_de_secours_2" ofType:#"mp4"]];
videoPlayer1 = [[MPMoviePlayerController alloc] initWithContentURL:fileUrl1];
videoPlayer2 = [[MPMoviePlayerController alloc] initWithContentURL:fileUrl2];
[self.scrollView addSubview:videoPlayer1.view];
scrollView.contentSize = CGSizeMake(self.view.frame.size.width *2, self.view.frame.size.height);
[self.view addSubview:scrollView];
[scrollView release];
First of all, it seems this line: [self.scrollView addSubview:videoPlayer1] is broken, I cannot add MPMoviePlayer to a UIView.
And second how can I set the frame for each video...the xOrigin and yOrigin?
I would appreciate a complete code with adding .mp4 files to a UIScrollView cause I cannot seem to make it work.
Thank you!:)

You should read the documentation first.
You're trying to add a controller instead of a view that's why it
doesn't work. I see that you have Android experience - it's like the difference between activity and view on android
If you still can't figure it out there's a lot of code for adding videos to views on the web, just search it. Don't see it necessary to add here such a generic code.

Related

UIWebview scalesPageToFit doesn't work perfectly

I'm using a small UIWebView, and scalesPageToFit doesn't work correctly for some url. (look like it cannot resize at 100%. (but if i zoom out the webview manually(gesture), it work!
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 400.0f)];
webViewT = [[UIWebView alloc] initWithFrame:view.bounds];
webViewT.delegate = self;
webViewT.scalesPageToFit = YES;
NSURL* url = [NSURL URLWithString:#"http://www.google.com/"];
[webViewT loadRequest:[NSURLRequest requestWithURL:url]];
Please note that i've found a solution:(below work, BUT I have the time to see a "resize"
- (void) webViewDidFinishLoad:(UIWebView *)webViewT {
if ([theWebView respondsToSelector:#selector(scrollView)])
{
UIScrollView *scroll=[theWebView scrollView];
float zoom=theWebView.bounds.size.width/scroll.contentSize.width;
[scroll setZoomScale:zoom animated:NO];
}
}
Any idea? Thanks!
In Some of cases this types of problem Generated. At that time java script use for control of Zoom of UIWebView, use following code.
NSString *jsCommand = [NSString stringWithFormat:#"document.body.style.zoom = 1.5;"];
[webLookupView stringByEvaluatingJavaScriptFromString:jsCommand];
Other way is
Refer this Answer UIWebView does not scale content to fit

UIWebview fitting to screen but not zooming in iphone programming

I am working on uiwebview and it is supposed to load dynamic urls coming from the server.
i want to show it fitting to the iPhone screen size in my iPhone application and also it should zoom in and out.
Code i am using for it is:
m_pView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 430)];
m_pView.backgroundColor = [UIColor blackColor];
self.view = m_pView;
UIWebView *aWebView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 1, 320, 400)] autorelease];
aWebView.dataDetectorTypes = UIDataDetectorTypeNone;
aWebView.delegate = self;
NSString* url = [NSString stringWithFormat: #"http://%#",[m_URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
aWebView.scalesPageToFit = YES;
aWebView.autoresizesSubviews = YES;
aWebView.frame = self.view.bounds;
NSURL *aURL = [NSURL URLWithString: url];
NSURLRequest *aRequest = [NSURLRequest requestWithURL:aURL];
//load the index.html file into the web view.
[aWebView loadRequest:aRequest];
[m_pView addSubview:aWebView];
self.m_webView = aWebView;
Please let me know how to achieve webview fitting to the iphone screen size without loosing zoom in/out feature.
Thanks in advance.
Use following code
yourWEbView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
yourWEbView.contentMode = UIViewContentModeScaleAspectFit;
problem might be in this line:
aWebView.frame = self.view.bounds;
Why you're setting bounds of self.view while adding webview to m_pView?

MediaPlayer Framework iOS SDK

I am trying to implement video into my app and I am having a hard time. I have tried this tutorial and it was super helpful.
But now when I try to run my app and click on the button, the video frame comes up and just stays black. My video is in the correct format, I also made sure that I am pulling in the MediaPlayer Framework. Has anyone ran into this issue before or knows why this would be happening?
This is what I have:
-(IBAction)playMovie:(id)sender
{
UIButton *playButton = (UIButton *) sender;
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"big-buck-bunny-clip" ofType:#"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view setFrame:CGRectMake(38, 100, 250, 163)];
[self.view addSubview:moviePlayerController.view];
//moviePlayerController.fullscreen = YES;
moviePlayerController.initialPlaybackTime = 5;
[moviePlayerController play];
}
Have you added MPMoviePlayerController's view onto your view?
MPMoviePlayerController *movieController = ...;
movieController.view.frame = self.view.bounds;
[self.view addSubview:movieController.view];
Frame could also be black if you've set shouldAutoplay to YES and controlStyle to MPMovieControlStyleNone
--Edit
This is how I init my player and it works, maybe that will be of some help. It's playing HTTP Live Streaming video, but it'll play anything you put into it. You should try the url in this sample. If it'll work then there's definitely some problem with your contentUrl.
url = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayerController.view.frame = self.view.bounds;
[self.view insertSubview:moviePlayerController.view atIndex:0];
moviePlayerController.controlStyle = MPMovieControlStyleNone;
moviePlayerController.shouldAutoplay = YES;
[moviePlayerController prepareToPlay];
I had the same problem, and also following the same tutorial, but then I found the class moviePlayerViewController that its easier to use and you don't even have to worry about dismiss buttons.
I fixed used the following code: (I think it works better with ios5)
self.moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:finalurl];
moviePlayerViewController.view.frame = self.view.bounds;
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
moviePlayerViewController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayerViewController.moviePlayer.shouldAutoplay = YES;
[moviePlayerViewController.moviePlayer prepareToPlay];
moviePlayerViewController.moviePlayer.fullscreen=YES;

Movie starts playing automatically?

I have added a movie to my view and it simply starts playing automatically, does anyone know how to stop this?
MPMoviePlayerController *moviePlayer;
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"LAN_S9" ofType:#"mp4"];
if (moviePath)
{
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[[moviePlayer view] setFrame: CGRectMake(0, 0, 400, 200)]; // frame must match parent view
}
[self.view addSubview: [moviePlayer view]];
Thats simple:
moviePlayer.shouldAutoplay = NO;
You cannot add a view of MPMoviePlayerController into your view because the MPMoviePlayerController always require full screen mode to play and it will auto jump into that mode.
So, you can extract an image from the film and then show the image with a nice Play button so user can tap on the button to view the video

inserting various views into UIScrollView

we're trying to implement an article detail view for an RSS-like application. The windows has a UIScrollView that contains a UITextView (which is the title), a UIButton (which opens a gallery), and a UIWebView (with the body). The idea is that all these elements scroll together...
The problem is that whenever we have a body over 1000px tall, everything below that mark is truncated. We've heard that this is because that is the maximum height for a view, and since the Scroll is handled by the top UIScrollView, there is no way to see what's further down.
does anybody know a way around this?
Thanks!
---- update 1 ----
We've broken up the body into 900px-high chunks, but all webviews after the first one show no content...
UIScrollView *scroll=[[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[scroll setBackgroundColor:[UIColor whiteColor]];
[scroll setCanCancelContentTouches:NO];
scroll.clipsToBounds = NO;
scroll.indicatorStyle = UIScrollViewIndicatorStyleBlack;
//Título
CGRect tit =CGRectMake(5.0f, 0.0f, 315.f, 50.0f);
UILabel *titulo=[[UILabel alloc] initWithFrame:tit];
titulo.text=[itemNew objectForKey:#"titulo"];
titulo.numberOfLines = 2;
titulo.font=[UIFont fontWithName:#"Helvetica" size:16.0f];
titulo.textColor=[self getColor:#"00336E"];
[scroll addSubview:titulo];
[titulo release];
//Entradilla
float altura_entradilla=calcLabel([itemNew objectForKey:#"entradilla"], [UIFont boldSystemFontOfSize:16], 50, 315.0f);
CGRect ent_frame = CGRectMake(5.0f, 50.0f, 315.0f,altura_entradilla );
UILabel *entradilla=[[UILabel alloc] initWithFrame:ent_frame];
entradilla.text=[itemNew objectForKey:#"entradilla"];
entradilla.numberOfLines=4;
entradilla.font=[UIFont fontWithName:#"Helvetica" size:17.0f];
entradilla.textColor=[UIColor blackColor];
[scroll addSubview:entradilla];
[entradilla release];
NSString *cuerpo=[itemNew objectForKey:#"cuerpo"];
[scroll setContentSize:CGSizeMake(320.0f,40000.0f)];
[scroll setScrollEnabled:YES];
webView = [[UIWebView alloc] initWithFrame:CGRectMake(5.0f, altura_entradilla+50, 315.0f, 900)];
[webView loadHTMLString:cuerpo baseURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
webView.detectsPhoneNumbers=NO;
webView.delegate=self;
[webView setScalesPageToFit:NO];
[scroll addSubview:webView];
webView.backgroundColor=[UIColor blackColor];
webView.userInteractionEnabled=NO;
[webView release];
if (altura_webview>900) {
UIWebView *webView2 = [[UIWebView alloc] initWithFrame:CGRectMake(5.0f, altura_entradilla+50+900, 315.0f, 900)];
[webView2 loadHTMLString:cuerpo baseURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
webView2.detectsPhoneNumbers=NO;
webView2.delegate=self;
[webView2 setScalesPageToFit:NO];
[scroll addSubview:webView2];
webView2.backgroundColor=[UIColor yellowColor];
webView2.userInteractionEnabled=NO;
[webView2 release];
}
self.view=scroll;
check the contentSize on your UIScrollview.
I've not heard of a 1000 point limit (or seen it in bigger views I have in our app).
Use more then one UIWebViews as body
Are you using loadHTMLString to add content to webView?
Try loadRequest method. There is no problem with 1024px when you are using loadRequest
I had the same problem and I read and tried a few tips of this thread, but neither loading the content via loadHTMLString, nor using [_webView setNeedsDisplay] did changed anything for me. (I should try loading more UIWebViews, but I'm lazy:)
I used a quick and dirty fix using the scrollview delegate, which did the trick:
#interface ArticleViewController : UIViewController <UIScrollViewDelegate>
then fire up the view in init
_scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = _scrollView;
_scrollView.delegate = self;
and use the delgate's method to redraw the webView as it shows up
- (void) scrollViewDidEndDragging: (UIScrollView *) scrollView willDecelerate: (BOOL) willDecelerate
{
CGRect frame = _webView.frame;
frame.size = CGSizeMake(frame.size.width, frame.size.height + 1);
_webView.frame = frame;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
CGRect frame = _webView.frame;
frame.size = CGSizeMake(frame.size.width, frame.size.height + 1);
_webView.frame = frame;
}
When you say :
We've tried breaking the body into several 900px-high webViews, but the second, third, etc. get blanked out (you can see the backgroundColor, but not the content)...
It seems to me that other persons have met this issue (I can't find the posts again), in fact UIWebviews seems to use only one HTML Interpreter. Meaning that if one UIWebView is loading HTML Content, others UIWebView won't load anything.
To solve that, you need to use UIWebView's delegate methods : didFinishLoad, and start loading the other webviews after that.
Please be aware that I'm not sure about what I'm saying, because I did not try it myself, but it might be a solution.
The post marked as the answer has a link in it's last comment. That is the solution to this problem. I had this very same problem, and invoking [[webView _documentView] _webCoreNeedsDisplay]; in those 2 delegates solved it. Cheers.