All
Technology
SEO
Design
Programming
iPhone
Android

MediaPlayer to play URL stored in SQLite

    Share on Facebook Create Topic
by Wally328
Hi,

I've been playing with extending the functionality to a very useful tutorial on SQLite:

Picked up a lot from this and thought that the detail view would benefit from having a 'play movie' button that uses a URL stored in the SQLite dB.

So, I have added a 'movie' column into the dB table and put in there URL links to videos on the web.

In the ViewController.m my code is:
[HTML]NSURL* theURL = [NSURL URLWithString:@"http://www.example.com/test.mp4"];
MoviePlayerController = [MPMoviePlayerController alloc];
MoviePlayerController = [MoviePlayerController initWithContentURL:theURL];[/HTML]

That code is fine for firing off MoviePlayer to launch and play a movie - I've tested, no probs. But of course, I don't want a hard-coded web URL in that code - every detail result page would have the same video effectively, I want it to take the URLs stated in the dB.

This is where I have problems.

In the tutorial the data is set-up in this passage:
[HTML]/ Setup the animation
[self.navigationController pushViewController:self.animalView animated:YES];
// Set the title of the view to the animal's name
self.animalView.title = [animal name];
// Set the description field to the animals description
[self.animalView.animalDesciption setText:[animal description]];
// Load the animals image into a NSData boject and then assign it to the UIImageView
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[animal imageURL]]];
UIImage *animalImage = [[UIImage alloc] initWithData:imageData cache:YES];
self.animalView.animalImage.image = animalImage;[/HTML]

after being introduced from dB at this point in tutorial:
[HTML]// Read the data from the result row
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];

// Create a new animal object with the data from the database
Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl];[/HTML]

What I really want to happen back in the ViewController is to know what tells the MoviePlayer where to get the dB URL.
Using off top of my head logic I want it to be something like this (but how do I get there):

[HTML]NSURL* theURL = [NSURL URLWithString:self.animalMovie];
MoviePlayerController = [MPMoviePlayerController alloc];
MoviePlayerController = [MoviePlayerController initWithContentURL:theURL];[/HTML]

I'm really struggling, I've posted to the tutorial page itself and not had this same message approved by moderator in over a week (maybe abandonded?)
Just nudging this tutorial on a touch to include this MediaPlayer aspect would be fantastic - really hope someone can explain and give a bit of a 'How To' reply.

Best regards ...
Home | Contact | Privacy Policy |