Loading Online Resources

Discussion in 'iOS Development' started by spoonforknife, Feb 4, 2009.

  1. spoonforknife

    spoonforknife Retired Moderator

    Joined:
    Nov 15, 2007
    Messages:
    6,896
    Likes Received:
    317
    How might I load a resource from online? Is this done differently than locally loaded resources?

    This works fine:

    Code:
    NSString *moviePath = [bundle pathForResource:@"video" ofType:@"mp4"];
    This fails miserably:

    Code:
    NSString *moviePath = [bundle pathForResource:@"http://webaddress.com/video" ofType:@"mp4"];
  2. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    try using NSURL

    Code:
    NSURL *movie = [NSURL URLWithString:[NSString stringWithFormat:@"http://blah.com/video.mp4"]];
  3. spoonforknife

    spoonforknife Retired Moderator

    Joined:
    Nov 15, 2007
    Messages:
    6,896
    Likes Received:
    317
    Hmm.. that didn't work.

    Here's what I have so far.

    Code:
    -(void)awakeFromNib {
    	
    	NSBundle *bundle = [NSBundle mainBundle];
    	
    	NSString *moviePath;
    
    	NSURL *movieURL [NSURL URLWithString:[NSString stringWithFormat:@"http://blah.com/video.mp4"]];;
    	
    	if (moviePath)
    	{
    		movieURL = [NSURL fileURLWithPath:moviePath];
    	}
    	
    	if (movieURL != nil) {
    		moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    		
    		// Register to receive a notification when the movie has finished playing. 
    		[[NSNotificationCenter defaultCenter] addObserver:self
    												 selector:@selector(moviePlayBackDidFinish:) 
    													 name:MPMoviePlayerPlaybackDidFinishNotification 
    												   object:moviePlayer];
    		
    		moviePlayer.scalingMode = MPMovieScalingModeAspectFill; 
    		moviePlayer.movieControlMode = MPMovieControlModeHidden;
    		moviePlayer.backgroundColor = [UIColor blackColor];
    		
    		[moviePlayer play];
    	}
    	
    }
    
    -(void)moviePlayBackDidFinish: (NSNotification*)notification
    {
    	moviePlayer = [notification object];
    }
    
  4. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    it should be

    NSURL *movieURL = [NSURL URLWithString

    Please Register or Log in to view images

    "http://blah.com/video.mp4"];
  5. spoonforknife

    spoonforknife Retired Moderator

    Joined:
    Nov 15, 2007
    Messages:
    6,896
    Likes Received:
    317
    Thanks!
  6. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    that's the same exact thing, except stringWithFormat provides more flexibility.
  7. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch

    stringWithFormat is not needed if you are not doing like %@
  8. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Code:
    char string[25] = {'h', 't', 't', 'p', ':', '/', '/', 'b', 'l', 'a', 'h', '.', 'c', 'o', 'm', '/', 'v', 'i', 'd', 'e', 'o', '.', 'm', 'p', '4', '\0' };
    NSString *movieURL = [NSString stringWithCString:string encoding:NSUTF8StringEncoding]; 
  9. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Haha, that would have been annoying to type up.
    I will use char string later though, i need this in my application

    Please Register or Log in to view images

    . Thanks.

Share This Page