Domanda

Nel tentativo di scaricare un video / audio su iPhone e conservare in iPhone fascio sistema e riprodurre il file video / audio dal fascio.

Ho scaricato con successo il file video / audio utilizzando NSURLConnection. e devo conservarla come "sample.mov"

, ma non ero in grado di riprodurre il video dal fascio. Forse perché il file non è stato registrato in bundle?!

Ecco il codice:

scrivere sul file quando completare il download

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"sample.mov"];

    [VideoData writeToFile:path atomically:YES];
}

poi ho riprodurre il video dal fascio

MoviePlayerAppDelegate *appDelegate = (MoviePlayerAppDelegate *)[[UIApplication sharedApplication] delegate];

    // play the movie
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"a" ofType:@"mov"];
    NSURL *movURL = [NSURL fileURLWithPath:moviePath];

    [appDelegate initAndPlayMovie:movURL];


-(void)initAndPlayMovie:(NSURL *)movieURL
{
    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    if (mp)
    {
        // save the movie player object
        self.moviePlayer = mp;
        [mp release];

        // Apply the user specified settings to the movie player object
        [self setMoviePlayerUserSettings];

        // Play the movie!
        [self.moviePlayer play];
    }
}
È stato utile?

Soluzione

A mia conoscenza non si può salvare con successo i file di risorse cartella di pacchetto.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top