Playing video and audio in iPhone not working...
        Posted  
        
            by Scott
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Scott
        
        
        
        Published on 2010-03-17T22:26:52Z
        Indexed on 
            2010/03/17
            22:31 UTC
        
        
        Read the original article
        Hit count: 336
        
So we have buttons linked up to display images/videos/audio on click depending on a check we do earlier. That part works fine. It knows which one to play, however, when we click the buttons for video and audio, nothing happens. The image one works fine.
The video and audio are being taken for a URL online, they are not local, but everywhere said this was still possible. Here is a little snippet of the code where we play the two files:
if ( [fName hasSuffix:@".png"])
    {
        NSLog(@"PICTURE");
        NSURL *url = [NSURL URLWithString: 
                      fName];
        UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
        self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        // self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"MainBG.jpg"]];
        [self.view addSubview:[[UIImageView alloc] initWithImage:image]];
    }
    if ( [fName hasSuffix:@".mp4"])
    {
        NSLog(@"VIDEO");
        //NSString *path = [[NSBundle mainBundle] pathForResource:fName ofType:@"mp4"];
        //NSLog(path);
        NSURL *url = [NSURL fileURLWithPath:fName];
        MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
        [player play];
    }
    if ( [fName hasSuffix:@".mp3"])
    {
        NSLog(@"AUDIO");
        NSURL *url = [NSURL fileURLWithPath:fName];
        NSData *soundData = [NSData dataWithContentsOfURL:url];
        AVAudioPlayer *avPlayer = [[AVAudioPlayer alloc] initWithData:soundData error: nil];
        [avPlayer play];
    }
See anything wrong? By the way it compiles and runs, but nothing happens when we hit the button that executes that code.
© Stack Overflow or respective owner