pathForResource Issue / Convert

Discussion in 'iPhone/iPad Programming' started by CeiJay, Jul 17, 2010.

  1. macrumors newbie

    CeiJay

    Joined:
    Jul 17, 2010
    #1
    I have been working on a problem from around 12 hours now and I am stumped. The first bit of code is the MoviePlayerViewController and the second bit is for Audio. The Second bit works when loading the path from an indexPath of a Table yet I cant get the first bit of code to do the same thing by loading from an Array.

    I need to convert this bit of code to...

    Code:
    // Play movie from the bundle
      NSString *path = [[NSBundle mainBundle] pathForResource:@"Movie-1" ofType:@"mp4" inDirectory:nil];
       
    	// Create custom movie player   
      moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:path] autorelease];
    
    	// Show the movie player as modal
     	[self presentModalViewController:moviePlayer animated:YES];
    
    	// Prep and play the movie
      [moviePlayer readyPlayer];    
    }
    This bite of code...

    Code:
    NSUInteger row = [indexPath row];
        NSString *rowTitle = [filmSound objectAtIndex:row];
    
    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], rowTitle]];
    	NSError *error;
    	AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
     
  2. thread starter macrumors newbie

    CeiJay

    Joined:
    Jul 17, 2010
    #2
    Thats make sense. Using the above the result works out to be...

    Code:
    NSInteger row = indexPath.row;
    NSString *rowTitle = [filmSound objectAtIndex:row];
    
    NSURL *url = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:rowTitle ofType:nil]];
    		
    		// Create custom movie player   
    moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:url] autorelease];
    Errors says struct NSURL expected NSString.

    What about this...

    How would one populate (the bold) with an array in any of these examples.

    Code:
    NSString *path = [[NSBundle mainBundle] pathForResource:@"INFO FROM ARRAY" ofType:@"mp4"];
    or

    Code:
    NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"INFO FROM ARRAY"];
    I can use the above within an If statement to populate a Cell depending on the indexPath yet the cells are editable and movable so I have a problem when it come to retaining the information for the move. If I have an array populating any of the above I can use an idObject to retain the info per cell.

    By changing the NSString *path to NSURL*path seem so never work as the MoviePlayerViewController I have written to handle all SDKs requires NSString.

    Thoughts?
     
  3. thread starter macrumors newbie

    CeiJay

    Joined:
    Jul 17, 2010
    #3
    Thank you for your help.

    The solution was the following...

    Code:
    NSInteger row = indexPath.row;
    	NSString *rowTitle = [filmMovie objectAtIndex:row];
    
    		NSString *path = [[NSBundle mainBundle] pathForResource:rowTitle ofType:nil];
     

Share This Page