I am trying to make an app that plays MP3 songs. My program flow is like this:
I have an XML file here in my website: http://jeewanaryal.web44.net/SongsXML/songsListXML.xml. It has song titles and the actual URL of those songs on the Internet. I have the following code for my Pop songs section:
NSString *urlString = #"http://jeewanaryal.web44.net/SongsXML/songsListXML.xml";
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
NSDictionary *dict = [XMLReader dictionaryForXMLData:data error:nil];
NSArray *arrayOfSongs = [[NSArray alloc] initWithArray:[[[dict objectForKey:#"list"] objectForKey:#"songs"] objectForKey:#"song"]];
StartStopSound = [UIButton buttonWithType:UIButtonTypeRoundedRect];
StartStopSound.frame = CGRectMake(60, 360, 200, 30);
[StartStopSound setTitle:#"बजाउनुहोस" forState:UIControlStateNormal];
[StartStopSound addTarget:self action:#selector(playSong) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:StartStopSound];
back = [UIButton buttonWithType:UIButtonTypeRoundedRect];
back.frame = CGRectMake(20, 320, 100, 30);
[back setTitle:#"पछाडीको गीत " forState:UIControlStateNormal];
[back addTarget:self action:#selector(playSong) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:back];
next = [UIButton buttonWithType:UIButtonTypeRoundedRect];
next.frame = CGRectMake(200, 320, 100, 30);
[next setTitle:#"अगाडीको गीत" forState:UIControlStateNormal];
[next addTarget:self action:#selector(playSong) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:next];
NSData *myData = [[NSData alloc] init ];
NSString *urlString1 = [[NSString alloc] init];
for (NSDictionary *fruitDict in arrayOfSongs) {
UILabel *songTitle = [[UILabel alloc] initWithFrame:CGRectMake(40, 200, 300, 40)];
songTitle.text = [NSString stringWithFormat:#"%#",[[fruitDict objectForKey:#"title"] objectForKey:#"text"]];
[self.view addSubview:songTitle];
urlString1 = [NSString stringWithFormat:#"%#",[[fruitDict objectForKey:#"url"] objectForKey:#"text"]];
//NSLog(#"\n\n -- URL STRING : %# \n\n",urlString);
}
myData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString1]];
player = [[AVAudioPlayer alloc] initWithData:myData error:nil];
[player play];
[player numberOfLoops];
[player currentTime];
This works fine for a single song; that is, it only plays the last URL of my XML file. I want to make all songs to be played one by one, making a "Next" and "Previous" button on my app.
Will you please tell me how I can implement that? I am using XMLReader.h and XMLReader.m file to parse the data from XML into my app.
You would need to store arrayOfSongs somewhere in the class. The "back" and "next" buttons would need separate actions (e.g. playPreviousSong, playNextSong). These methods would then look something like this:
-(void) playPreviousSong
{
NSString *url = [[self songs] objectAtIndex:[self songIndex] - 1];
[self playSong:url];
[self setSongIndex:[self songIndex - 1];
}
This is a crude implementation just to show how it'd fit together. Basically you need to store the list of songs and keep track of which song is "selected"/playing, then just select the next/previous one.
Edit: To answer your question in the comments, you have already extracted the array of song URLs, you simply need to keep a reference to it in the class. E.g.
#interface AudioPlayer {
NSArray *_songs;
NSUInteger *_songIndex;
}
Then in the #implementation instead of creating a arrayOfSongs variable, simply reference the array from the instance variable:
_songs = [[NSArray alloc] initWithArray:[[[dict objectForKey:#"list"] objectForKey:#"songs"] objectForKey:#"song"]];
Then in, for example, the playPreviousSong method:
-(void) playPreviousSong
{
NSString *url = [_songs objectAtIndex:_songIndex - 1];
[self playSong:url];
_songIndex--;
}
Related
I have wired up a UIStackView in my storyboard and I am dynamically adding buttons to it, this works fine if I add one or two buttons but when I want to insert the third button the app crashes with the following error
017-12-27 10:41:14.315786+0800 NWMPos[39434:24150577] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'index out of bounds for arranged subview: index = 2 expected to be less than or equal to 1'
*** First throw call stack:
(0x187151d04 0x1863a0528 0x187151c4c 0x190ce44c4 0x104ec1fdc 0x106ae549c 0x106ae545c 0x106aea050 0x1870f9eb0 0x1870f7a8c 0x187017fb8 0x188eaff84 0x1905ec2e8 0x104ec4620 0x186b3a56c)
libc++abi.dylib: terminating with uncaught exception of type NSException
I have not specified anywhere (that I know of) a limit of 2 entries in the stackview so I am a bit lost here as to why I can add two buttons but not a third
Below is the code that adds the buttons
dispatch_async(dispatch_get_main_queue(), ^{
_fcVariantImageView.image = nil;
if ([finalUrl hasPrefix:#"https"]) {
NSURL *url = [[NSURL alloc] initWithString:[finalUrl stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSData *data =[NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
_fcVariantImageView.contentMode = UIViewContentModeScaleAspectFit;
_fcVariantImageView.image = image;
} else {
_fcVariantImageView.image = [UIImage imageNamed:fcVariantRow[#"fcVariantImageUrl"]];
}
if ([finalSwatchUrl hasPrefix:#"https"]) {
NSURL *url = [[NSURL alloc] initWithString:[finalSwatchUrl stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSData *data =[NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
UIButton *imageButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
imageButton1.tag = 1;
imageButton1.frame = CGRectMake(0, 0, 4, 4);
[imageButton1 setImage:image forState:UIControlStateNormal];
[imageButton1 addTarget:self action:#selector(buttonPushed:) forControlEvents:UIControlEventTouchUpInside];
[_fcVariantColourStackView insertArrangedSubview:imageButton1 atIndex:0];
}
// If 2 variants we need add a second swatch
if(numberOfVariants == 2) {
NSDictionary *fcVariantRow2 = [_fullConceptVariants objectAtIndex:1];
//NSString *finalUrl2 = [NSString stringWithFormat:#"https:%#", fcVariantRow2[#"fcVariantImageUrl"]];
NSString *finalSwatchUrl2 = [NSString stringWithFormat:#"https:%#", fcVariantRow2[#"fcVariantSwatch"]];
if ([finalSwatchUrl2 hasPrefix:#"https"]) {
NSURL *url2 = [[NSURL alloc] initWithString:[finalSwatchUrl2 stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSData *data2 =[NSData dataWithContentsOfURL:url2];
UIImage *image2 = [UIImage imageWithData:data2];
UIButton *imageButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
imageButton2.tag = 2;
imageButton2.frame = CGRectMake(0, 0, 4, 4);
[imageButton2 setImage:image2 forState:UIControlStateNormal];
[imageButton2 addTarget:self action:#selector(buttonPushed:) forControlEvents:UIControlEventTouchUpInside];
[_fcVariantColourStackView insertArrangedSubview:imageButton2 atIndex:1];
}
}
// If 3 variants we need add a third swatch
if(numberOfVariants == 3) {
NSDictionary *fcVariantRow3 = [_fullConceptVariants objectAtIndex:2];
NSString *finalSwatchUrl3 = [NSString stringWithFormat:#"https:%#", fcVariantRow3[#"fcVariantSwatch"]];
if ([finalSwatchUrl3 hasPrefix:#"https"]) {
NSURL *url3 = [[NSURL alloc] initWithString:[finalSwatchUrl3 stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSData *data3 =[NSData dataWithContentsOfURL:url3];
UIImage *image3 = [UIImage imageWithData:data3];
UIButton *imageButton3 = [UIButton buttonWithType:UIButtonTypeCustom];
imageButton3.tag = 3;
imageButton3.frame = CGRectMake(0, 0, 4, 4);
[imageButton3 setImage:image3 forState:UIControlStateNormal];
[imageButton3 addTarget:self action:#selector(buttonPushed:) forControlEvents:UIControlEventTouchUpInside];
[_fcVariantColourStackView insertArrangedSubview:imageButton3 atIndex:2];
}
}
_fcVariantDescriptionLbl.text = fcVariantRow[#"fcVariantName"];
_fcVariantViewItemId.text = fcVariantRow[#"fcVariantItemId"];
_fcVariantViewPriceLbl.text = [NSString stringWithFormat:#"%# %#", [NWTillHelper getCurrencySymbol], fcVariantRow[#"fcVariantPrice"]];
_fcSelectedColorLbl.text = fcVariantRow[#"fcVariantColourDescription"];
[_fcVariantSpinner stopAnimating];
});
I would like to present to the user with each press of the button different letter from the ABC.
So when it first click on the application the user will see the letter A, then they will need to press the button and then they will see the letter B and so forth.
My challenge is how to replace the text of the title with each click on the button.
I wrote down some code, of two functions, if you will take a closer look you will see that -(void)displayABC:(id)sender is getting called each time so each time I getting the first member of the array, so first time the user see the letter A then it press on the button and she/he see the letter B which is the first member of the array, but each the same letter is been presented because each time, we loading the plist file and therefore we keep calling the first member of the array.
Any ideas how to solve it?
-(void)createLoginBioButton
{
authButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[authButton setBounds:CGRectMake(300,300, 150, 150)];
[authButton setCenter:CGPointMake(150, 240)];
[self.view addSubview:authButton];
[authButton setEnabled:true];
[authButton setTitle:#"A" forState:UIControlStateNormal];
[authButton setFont:[UIFont systemFontOfSize:70]];
[authButton addTarget:self
action:#selector(displayABC:)
forControlEvents:UIControlEventAllTouchEvents];
}
-(void)displayABC:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"ABC" ofType:#"plist"];
NSArray *ABCArray = [NSArray arrayWithContentsOfFile:path];
for (NSString *ABCValues in ABCArray){
[authButton setTitle:ABCValues forState:UIControlStateNormal];
}
}
Why not keep a reference to the current letter index as an instance variable and increment that with each touch?
Psuedo code
#property NSArray *abcs;
#property int currentIndex;
- (void)viewDidLoad {
[super viewDidLoad];
self.abcs = //load it from the plist
[self updateButtonText];
}
- (void)buttonTouched
{
self.currentIndex++;
if ( self.currentIndex >= self.abcs.count ) {
self.currentIndex = 0;
}
[self updateButtonText];
}
- (void)updateButtonText
{
[self.button setTitle:self.abcs[self.currentIndex] forControlState:UIControlStateNormal];
}
Simplest solution would be to put a static variable which keeps tracking index
-(void)createLoginBioButton
{
authButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[authButton setBounds:CGRectMake(300,300, 150, 150)];
[authButton setCenter:CGPointMake(150, 240)];
[self.view addSubview:authButton];
[authButton setEnabled:true];
[authButton setTitle:#"A" forState:UIControlStateNormal];
[authButton setFont:[UIFont systemFontOfSize:70]];
[authButton addTarget:self action:#selector(displayABC:) forControlEvents:UIControlEventAllTouchEvents];
}
-(void)displayABC:(id)sender
{
static int index = 0;
NSString *path = [[NSBundle mainBundle] pathForResource:#"ABC" ofType:#"plist"];
NSArray *ABCArray = [NSArray arrayWithContentsOfFile:path];
if(index < [ABCArray count])
[authButton setTitle:[ABCArray objectAtIndex:index] forState:UIControlStateNormal];
index++;
}
I want to reload(refresh) my mainviewcontroller after changes. I add some data to data model and after save operation I put buttons to data elements on my main view. In second controller I make a edition section in which I change or delate data from base. My question is: How can I reload main view after delating element from base. My code for creating buttons is in mainviewcontroller:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Destination" inManagedObjectContext:_managedObjectContext];
[request setEntity:entity];
NSError *error = nil;
mutableFetchResults = [[_managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
CGFloat y = 130.;
for (int i = 0; i < [mutableFetchResults count]; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:#"ikonki%d.png",i]] forState:UIControlStateNormal];
[button setTitle:#"Test" forState:UIControlStateNormal];
NSLog(#"%#",_destination3.nazwa);
[button setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];
[button setEnabled:YES];
[button addTarget:self
action:#selector(buttonHandler:)
forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
button.frame = CGRectMake(x, y, 64 , 64);
Do you know NSFetchedResultsController? Go to documentation and look at DataSectionTitles and iPhoneCoreDataRecipes samples. Here you can find how to use this class. Basically this class gets your fetch request, listens for changes and if you delete / insert / update / ... objects in your NSManagedObjectContext it triggers delegate methods where you can update your view.
I'm parsing my data on this way:
NSDictionary *item = [tableData objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[item objectForKey:#"title"]];
[[cell detailTextLabel] setText:[item objectForKey:#"description"]];
But is there a way to parse an cell image? Normally it's
UIImage *cellImage = [UIImage imageNamed:#"image.png"];
cell.imageView.image = cellImage;
But i'm searching for a way like
[[cell UIImage cellimage] ....
Something like that so i can parse an image url from json in it
is that possible?
NSURL *url = [NSURL URLWithString:[item objectForKey:#"image"]];
NSData *data = [NSData dataWithContentsOfURL:url];
cell.imageView.image = [UIImage imageWithData:data];
Set a max width for the image
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar // called when keyboard search button pressed
{
[spinner startAnimating];
spinner.hidden=NO;
NSLog( #" Searchbar text = %#",searchBar.text);
strSearch=searchBar.text;
strSearch=[strSearch stringByReplacingOccurrencesOfString:#" " withString:#"+"];
[searchBar resignFirstResponder];
[self searchGooglePhotos];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar // called when cancel button pressed
{
[searchBar resignFirstResponder];
}
-(void)searchGooglePhotos
{
// Build the string to call the Flickr API
NSString *urlString = [NSString stringWithFormat:#"http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=%#",strSearch];
NSLog(#"urlarrystring is := %#",urlString);
// Create NSURL string from formatted string
NSURL *url = [NSURL URLWithString:urlString];
// Setup and start async download
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection release];
[request release];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// Store incoming data into a string
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// Create a dictionary from the JSON string
NSDictionary *respone = [jsonString JSONValue];
//NSLog(#"result dict is :%#",respone);
// Build an array from the dictionary for easy access to each entry
urlarry = [[[respone valueForKey:#"responseData"] valueForKey:#"results"]valueForKey:#"url"];
NSArray *title = [[[respone valueForKey:#"responseData"] valueForKey:#"results"]valueForKey:#"title"];
MoreUrlarry=[[[respone valueForKey:#"responseData"] valueForKey:#"cursor"]valueForKey:#"moreResultsUrl"];
[urlarry retain];
NSLog(#"photourlarry is :%#",urlarry);
NSLog(#"phototitle is :%#",title);
NSLog(#"photoMoreUrlarry is :%#",MoreUrlarry);
NSData *data2;
NSString *str=[[NSString alloc] init];
[scrl removeFromSuperview];
[displayview removeFromSuperview];
scrl=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 44,320, 430)];
[scrl setContentSize:CGSizeMake(320*[urlarry count], 430)];
scrl.pagingEnabled=YES;
//==========
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Assign activity indicator to the pre-defined property (so it can be removed when image loaded)
//self.activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(55, 67, 25, 25)];
// Start it animating and add it to the view
// Create multiple imageviews to simulate a 'real' application with multiple images
CGFloat verticalPosition = 10;
int i = 1;
for (i=1; i<5; i++) {
// Set vertical position of image in view.
if (i > 1) {
verticalPosition = verticalPosition+85;
}
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(122, verticalPosition, 80, 80)];
imageView.tag = i;
[self.view addSubview:imageView];
// set the image to be loaded (using the same one here but could/would be different)
NSString *str123=[urlarry objectAtIndex:i-1];
NSURL *imgURL = [NSURL URLWithString:str123];
// Create an array with the URL and imageView tag to
// reference the correct imageView in background thread.
NSMutableArray *arr = [[NSArray alloc] initWithObjects:imgURL, [NSString stringWithFormat:#"%d", i], nil ];
// Start a background thread by calling method to load the image
[self performSelectorInBackground:#selector(loadImageInBackground:) withObject:arr];
}
[pool release];
/*
int x=10,y=50,p=250,q=20;
for (int i=0; i<[urlarry count]; i++)
{
str=[NSString stringWithString:[urlarry objectAtIndex:i]];
data2 = [NSData dataWithContentsOfURL:[NSURL URLWithString:str]];
Favimage = [[UIImage alloc]initWithData:data2];
markButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[markButton setFrame:CGRectMake(p, q, 35,20)];
markButton.tag=i;
NSLog(#"tag is :%d",markButton.tag);
//[imgButton setTitle:[NSString stringWithFormat:#"%i",i] forState:UIControlStateNormal];
//imgButton.contentMode=UIViewContentModeScaleAspectFit;
// [imgButton setBackgroundImage:[UIImage imageNamed:#"no.png"]forState:UIControlStateNormal];
//[imgButton setImage:[Favimage imageScaledToFitSize:CGSizeMake(300, 320)] forState:UIControlStateNormal];
[markButton addTarget:self action:#selector(mark_buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[scrl addSubview:markButton];
UIButton *imgButton = [UIButton buttonWithType:UIButtonTypeCustom];
[imgButton setFrame:CGRectMake(x, y, 300,320)];
imgButton.tag=i;
NSLog(#"tag is :%d",imgButton.tag);
//[imgButton setTitle:[NSString stringWithFormat:#"%i",i] forState:UIControlStateNormal];
imgButton.contentMode=UIViewContentModeScaleAspectFit;
// [imgButton setBackgroundImage:[UIImage imageNamed:#"no.png"]forState:UIControlStateNormal];
[imgButton setImage:[Favimage imageScaledToFitSize:CGSizeMake(300, 320)] forState:UIControlStateNormal];
[imgButton addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
//[imgButton setImage:Favimage forState:UIControlStateNormal];
[scrl addSubview:imgButton];
//UIImageView *imageview=[[UIImageView alloc] initWithFrame:CGRectMake(x, y, 90, 90)];
// [imageview setImage:Favimage];
// [scrl addSubview:imageview];
NSLog(#"value of x=%d",x);
NSLog(#"value of y=%d",y);
NSLog(#"value of p=%d",p);
NSLog(#"value of q=%d",q);
NSLog(#"str is : %#",str);
if (y>=30 )
{
//x=15;
x=x+320;
}
if (q>=0 )
{
//x=15;
p=p+320;
}
//else
// {
// y=y+;
// }
}*/
[spinner stopAnimating];
spinner.hidden=TRUE;
[self.view addSubview:scrl];
btnmore.hidden=NO;
//NSLog(#"str is : %#",str);
// NSLog(#"j is : %d",j);
// NSLog(#"p is : %d",p);
}
- (void) loadImageInBackground:(NSArray *)urlAndTagReference {
NSLog(#"Received URL for tagID: %#", urlAndTagReference);
// Create a pool
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Retrieve the remote image. Retrieve the imgURL from the passed in array
NSData *imgData = [NSData dataWithContentsOfURL:[urlAndTagReference objectAtIndex:0]];
UIImage *img = [[UIImage alloc] initWithData:imgData];
// Create an array with the URL and imageView tag to
// reference the correct imageView in background thread.
NSMutableArray *arr = [[NSArray alloc] initWithObjects:img, [urlAndTagReference objectAtIndex:1], nil ];
// Image retrieved, call main thread method to update image, passing it the downloaded UIImage
[self performSelectorOnMainThread:#selector(assignImageToImageView:) withObject:arr waitUntilDone:YES];
}
- (void) assignImageToImageView:(NSArray *)imgAndTagReference
{
// Create a pool
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// loop
for (UIImageView *checkView in [self.view subviews] ) {
NSLog(#"Checking tag: %d against passed in tag %d",[checkView tag], [[imgAndTagReference objectAtIndex:1] intValue]);
if ([checkView tag] == [[imgAndTagReference objectAtIndex:1] intValue]) {
// Found imageView from tag, update with img
[checkView setImage:[imgAndTagReference objectAtIndex:0]];
//set contentMode to scale aspect to fit
checkView.contentMode = UIViewContentModeScaleAspectFit;
//change width of frame
CGRect frame = checkView.frame;
frame.size.width = 80;
checkView.frame = frame;
}
}
// release the pool
[pool release];
// Remove the activity indicator created in ViewDidLoad()
//[self.activityIndicator removeFromSuperview];
}
-(void)buttonPressed:(id)sender
{
UIButton *imgButton = (UIButton *)sender;
int q=imgButton.tag;
string=[[NSString alloc] init];
string=[NSString stringWithString:[urlarry objectAtIndex:q]];
// NSLog(#"aap str is :%#",appDel.appstr);
// [self.navigationController pushViewController:objimv animated:YES];
}
I have ten image files and sound files, and when I display "a.png" I want to play "a.mp3". Then when I click a "Next" button, display "b.png" and play "b.mp3". How can I solve this?
-(void) viewDidLoad;{
sounds = [[NSArray alloc]initWithObjects:#"a.mp3", #"b.mp3",#"c.mp3", nil];
imageArray = [[NSArray arrayWithObjects:
[UIImage imageNamed:#"a.jpg"],
[UIImage imageNamed:#"b.jpg"],
[UIImage imageNamed:#"c.jpg"],
nil] retain];
[super viewDidLoad];}
-(IBAction) next; {
currentSound++;
if (currentSound >= sounds.count) currentSound = 0;
//what kind of code play this sound////images work perpectly but sound not//
currentImage++;
if (currentImage >= imageArray.count) currentImage = 0;
UIImage *img = [imageArray objectAtIndex:currentImage];
[imageView setImage:img];}
To play the sound, use this
type this in your .h file:
AVAudioPlayer *theaudio;
and this goes in your .m, when you want to play the music
NSString *path = [[NSBundle mainBundle] pathForResource:#"nameofmusicfile" ofType:#"mp3"];
theaudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[path release];
[theaudio play];
to stop it, use [theaudio stop];
to display the image use UIImageView *i;
i = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"image.png"]];
to put it on - [view addSubview: i];
to move it i.center = CGPointMake(0.0,0.0);