Preview of the ringtone - iphone

This is my first question, & i am new to iOS Development. I wanted to ask how can i play preview of the ringtone when tapped on a cell in table view on iphone.
Basically i am trying to write an app which allows downloading of ringtone from my server on iphone, in that i want to add a preview feature, through which person will be able to listen the tone if he likes he will download. then he will be able to set it as ringtone.
I have managed to get the links of tones, on my server in a table view. now i want to play preview. how can i do that??
Request: please describe as i am newbie. not an advance programmer.
please ignore my mistakes.
Regards,
Malhaar
edit: i am using this code..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:[[ringArray objectAtIndex:indexPath.row]getName]
ofType:#"m4r"]];
AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
[click play];
[click release];
}

There are not too many details given, but at a high level, you would want to do the following:
1) Implement the "tableView:didSelectRowAtIndexPath:" delegate method of UITableView in order to respond to touches on the table cells.
2) Obtain the data for the ringtone. You could do this using NSURLConnection.
3) Play the ringtone using AVFoundation, specifically AVAudioPlayer.

Related

"Plays Sound" Property of UIButton in Interface Builder

in interface builder there is property of UIButton under Accessibility that says "Plays Sound".
Can any one explain what is this. Actually i am making an application which play sound on every button click and i can disable sounds from setting screen. Will this property of UIButton can help me?
Thanks
You can use [[UIDevice currentDevice] playInputClick]; to play the keyboard input click sound which is available in UIDevice. Check this apple documentation for more details.
You need to do the following for this,
Adopt the UIInputViewAudioFeedback protocol in your input view class.
Implement the enableInputClicksWhenVisible delegate method to return YES.
Do this in UIView class,
#interface MyView : UIView <UIInputViewAudioFeedback>
Then implement enableInputClicksWhenVisible method
- (BOOL)enableInputClicksWhenVisible
{
return YES;
}
If you are facing issues with this, you can check this.
The answer to your original question of whether you can use the Plays Sound 'property' (it's probably not actually a property) to make your buttons play sound is: No. Plays Sound is a 'Trait' that describes the Accessibility of an object (in this case a button) for people who are using VoiceOver (i.e. most likely people who are blind). You can read the documentation here.
hey you want to play sound on button click event then use bellow code also..
-(IBAction)playSound:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"adriantnt_release_click" ofType:#"mp3"]; /// set .mp3 name which you have in project
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
and use like bellow..
-(IBAction)yourButton_Clicked:(id)sender
{
[self performSelector:#selector(playSound:) withObject:sender];
//your code write here
}
Note: Add AudioToolbox.framework Framework And also import
#import<AVFoundation/AVAudioPlayer.h> in .h file and also add Delegate AVAudioPlayerDelegate in .h file
i hope this help you...

Clickable links in UITableView that open up Safari

I am working on an iPhone app, and would like to be able to click on a link that is in UITableView. When the Link, and only the link is selected I want the Safari app to be opened to the selected link. Any suggestions on how to do this? Thanks so much!
There are multiple solutions to your problem.
If the links are the only object in the cell, then you could just make call the didSelectRowAtIndexPath:(NSIndexPath *)indexPath function of UITableView to gather the link from your array of table data, and then use
[[UIApplication sharedApplication] openURL:myURL];
to open the URL.
Alternatively you could create your own UITableCell subclass that contains a custom button (instead of a rounded rect button) that has no image or background (only text) so that it has the appearance of a link (you could even color the text blue, and underline it...). When the user clicks the button, your handler function would then call the same openURL function as above.
The above method works best if you have multiple items in each cell (which is why you would have to create a custom cell...
A naive approach would be to embed a tiny UIWebView into each cell. UIWebView has a delegate that lets you know when a link is clicked which you can implement to launch the Safari or navigate to a new controller hosting a full screen UIWebView.
This approach might be too resource intensive and I haven't tried it myself but if it does work it would offer a lot of flexibility. Would love to know the results if you try it.
To launch a link in safari use:
NSURL *url = [NSURL URLWithString:#"http://stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(#"%#%#", #"Failed to open url:", [url description]);
}
Is the link in its own row in the UITableView? If so, then you can handle it within didSelectRowAtIndexPath when the appropriate row is clicked.

MPMoviePlayerController problem when play a movie

i put a movie when my application will lunch . just like gameloft games .
so when application has lunched , movie plays fine but before the move plays .. my FirstViewController xib file show first then moview start to play ! why ?
here is my code :
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"movie" ofType:#"m4v"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *IntroMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
IntroMovie.movieControlMode = MPMovieControlModeHidden;
[IntroMovie play];
}
Your question is a little unclear, but what I think you are asking is why your movie is not playing when the application launches before the user sees the controls and items in your XIB file. If this is correct, then this is the normal behavior as typically the application will launch and only then call the function you have (applicationDidFinishLaunching). There is no guarantee that you will get that function called before the controls have loaded and are viewable on the screen all the time.
It is bad form to start you application with a movie, but if you want to then you have to deal with the fact that there will potentially be a default image or even your controls that you put in your XIB file.
One way to start with a movie, is that you must hide or delete everything in the XIB file so the screen will appear blank when the application loads. Then, when you application calls the applicationDidFinishLaunching function the user will not have seen your application and the first thing they will see is the movie. When the movie is finished playing, you will need to have a notification listener instruct your application to show the controls for your application or switch to another XIB file that has the app controls within it.
I hope this helps.

Make AVFoundation framework not fading when screen fades

I am implementing some audiobooks for iPhone. I used AVFoundation. Something like this:
NSString *path = [[NSBundle mainBundle] pathForResource:#"intro" ofType:#"mp3"];
player=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
I have a problem. When the screen goes dark (single audio files can be very long) the audio stops playing.
I solved this problem with this string of code
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// something else here...
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}
This does not allow the iPhone to "sleep". However you can guess how this is foolish: your battery level goes down in minutes and this is not possible by audiobooks lasting more than 20 hours, for example...
So, do you know a way to prevent that when the screen sleeps the AVAudioPlayer does not stop playing?
Thanks...
Fabio
Set your audio session to kAudioSessionCategory_MediaPlayback to playback while the screen is locked.
Could I suggest that once you start playing the audio file that you tell the user to press the power button (not home button) which will lock the phone. It will not close you app but it will power off the screen with you application running in the background. Currently several apps do this.

Audio volume stuck at low level and adjusting volume has no effect?

When I use my app (on the device), the actual volume works OK for a while, but after a few days it seems to get 'stuck' at a low level.
Adjusting the volume rocker has no effect - and it shows 'Ringer' text. I've noticed that other people's apps are similarly affected if they show the 'Ringer' text when adjusting the volume. But apps which don't show 'Ringer' text are not affected by this.
How would I remove the 'Ringer' text and get my app to respond properly to different volumes?
I found some code on Apple's forums which fixes it. You have to use the AVFoundation.framework and put a bit of code into your app delegate. And put an audio file called 'blank.aif' into your project. Basically, it's a hack which prepares a file to play, but then never plays it. This fools the system into thinking that sound is being played all the time, which allows the user to use the main volume control.
#import <AVFoundation/AVFoundation.h>
//...
-(void)applicationDidFinishLaunching:(UIApplication *)application {
//volume control hack
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"blanksound" ofType:#"aif"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath];
AVAudioPlayer *volumeHack = [[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]retain];
[fileURL release];
[volumeHack prepareToPlay];
// other applicationDidFinishLaunching stuff
}