Playing a Sound While App Runs - ios

EDITED
still not sure whats wrong please help
hi there I'm creating and iOS application and trying to make it play a sound when running I've type up my code in the app delegate .h , .m and it plays the sound fine but the thing is it goes to a black screen when my ViewController.xib has a blue background heres heres the code i have
AppDelegate.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#class ViewController;
#interface AppDelegate : NSObject <UIApplicationDelegate, AVAudioPlayerDelegate> {
UIWindow *window;
ViewController *viewController;
AVAudioPlayer *_backgroundMusicPlayer;
BOOL _backgroundMusicPlaying;
BOOL _backgroundMusicInterrupted;
UInt32 _otherMusicIsPlaying;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet ViewController *viewController;
- (void)tryPlayMusic;
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize viewController = _viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Set up the audio session
// See handy chart on pg. 55 of the Audio Session Programming Guide for what the categories mean
// Not absolutely required in this example, but good to get into the habit of doing
// See pg. 11 of Audio Session Programming Guide for "Why a Default Session Usually Isn't What You Want"
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&setCategoryError];
// Create audio player with background music
NSString *ticktockPath = [[NSBundle mainBundle] pathForResource:#"ticktock" ofType:#"wav"];
NSURL *ticktockURL = [NSURL fileURLWithPath:ticktockPath];
NSError *error;
_backgroundMusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:ticktockURL error:&error];
[_backgroundMusicPlayer setDelegate:self]; // We need this so we can restart after interruptions
[_backgroundMusicPlayer setNumberOfLoops:-1]; // Negative number means loop forever
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
- (void) audioPlayerBeginInterruption: (AVAudioPlayer *) player {
_backgroundMusicInterrupted = YES;
_backgroundMusicPlaying = NO;
}
- (void) audioPlayerEndInterruption: (AVAudioPlayer *) player {
if (_backgroundMusicInterrupted) {
[self tryPlayMusic];
_backgroundMusicInterrupted = NO;
}
}
- (void)applicationDidBecomeActive:(NSNotification *)notification {
[self tryPlayMusic];
}
- (void)tryPlayMusic {
// Play the music if no other music is playing and we aren't playing already
if (_otherMusicIsPlaying != 1 && !_backgroundMusicPlaying) {
[_backgroundMusicPlayer prepareToPlay];
[_backgroundMusicPlayer play];
_backgroundMusicPlaying = YES;
}
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
#end
ok so thats all the code
and heres what i get when app loads and the sound works fine
and this is what i want to get (ViewController.xib)
Thank in advanced
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&setCategoryError];
self.viewController = [[ViewController alloc] init];
// Create audio player with background music
NSString *ticktockPath = [[NSBundle mainBundle] pathForResource:#"ticktock" ofType:#"wav"];
NSURL *ticktockURL = [NSURL fileURLWithPath:ticktockPath];
NSError *error;
_backgroundMusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:ticktockURL error:&error];
[_backgroundMusicPlayer setDelegate:self]; // We need this so we can restart after interruptions
[_backgroundMusicPlayer setNumberOfLoops:-1]; // Negative number means loop forever
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
new code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

You never initialized your view controller.
Somewhere before you do
[window addSubview:viewController.view];
You need to do
self.viewController = [[ViewController alloc] init];
I see that you declared the property as an IBOutlet.. is it actually hooked up to something in Interface Builder?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&setCategoryError];
// Create audio player with background music
NSString *ticktockPath = [[NSBundle mainBundle] pathForResource:#"ticktock" ofType:#"wav"];
NSURL *ticktockURL = [NSURL fileURLWithPath:ticktockPath];
NSError *error;
_backgroundMusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:ticktockURL error:&error];
[_backgroundMusicPlayer setDelegate:self]; // We need this so we can restart after interruptions
[_backgroundMusicPlayer setNumberOfLoops:-1]; // Negative number means loop forever
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Copy that function and just delete this one - (void)applicationDidFinishLaunching:(UIApplication *)application completely.
You should also consider converting your project to use ARC. It will remove the need to retain/release/autorelease statements.

You have two targets - are all your resources included in the target that you're building?

Related

AVPlayer Works on Simulator, but not on device

playerItem=[AVPlayerItem playerItemWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://www.radio.com.lk/y-fm/"]]];
player=[AVPlayer playerWithPlayerItem:playerItem] ;
[player play];
It's working on Simulator but in the device, it's not. In the console,
I have the following error:
CredStore - performQuery - Error copying matching creds.
Error=-25300, query={
class = inet;
"m_Limit" = "m_LimitAll";
"r_Attributes" = 1;
sync = syna; }
Can anyone help me with a clue?
Please add below code in your app delegate. It may help you
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&activationError];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&setCategoryError];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}
My answer is for you
ViewController.h
#import <UIKit/UIKit.h>
#import <AVKit/AVKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) AVPlayerViewController *playerViewController;
#property (nonatomic,strong)AVAudioPlayer *player;
- (IBAction)actionPlay:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize player;
#synthesize playerViewController;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)actionPlay:(id)sender {
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:yourURL];
AVPlayer* playVideo = [[AVPlayer alloc] initWithPlayerItem:playerItem];
playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = playVideo;
playerViewController.player.volume = 0;
playerViewController.view.frame = self.view.bounds;
[self.view addSubview:playerViewController.view];
[playVideo play];
}

Prevent iOS webview from going BACK under status bar

I have a phonegap/cordova app and when I call the ChildBrowser from the app, exit the childbrowser, and go back to app, the webview goes under status bar.
There are a million answers as to how to prevent webview (in iOS7 and later) from going under status bar. That is not the issue here because initially the app is fine and its webview is not overlapping with the status bar.
The issue happens only after exiting the childbrowser.
Basic flow:
Launch app (all is fine) -> call ChildBrowser (from app) -> Exit ChildBrowser -> back to app (PROBLEM: webview under status bar).
Please ask for clarifications and please advise.
AppDelegate.m
/*
Licensed to the Apache Software Foundation (ASF) under one
...
*/
//
// AppDelegate.m
#import "AppDelegate.h"
#import "MainViewController.h"
#ifdef CORDOVA_FRAMEWORK
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVURLProtocol.h>
#else
#import "CDVPlugin.h"
#import "CDVURLProtocol.h"
#endif
#implementation AppDelegate
#synthesize window, viewController;
- (id) init
{
/** If you need to do any extra app-specific initialization, you can do it here
* -jm
**/
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
[CDVURLProtocol registerURLProtocol];
return [super init];
}
#pragma UIApplicationDelegate implementation
/**
* This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
*/
- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSString* invokeString = nil;
if (url && [url isKindOfClass:[NSURL class]]) {
invokeString = [url absoluteString];
NSLog(#"ios-cordova-childbrowser launchOptions = %#", url);
}
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
self.window.autoresizesSubviews = YES;
CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];
self.viewController = [[[MainViewController alloc] init] autorelease];
self.viewController.useSplashScreen = YES;
self.viewController.wwwFolderName = #"www";
self.viewController.startPage = #"index.html";
self.viewController.invokeString = invokeString;
self.viewController.view.frame = viewBounds;
// check whether the current orientation is supported: if it is, keep it, rather than forcing a rotation
BOOL forceStartupRotation = YES;
UIDeviceOrientation curDevOrientation = [[UIDevice currentDevice] orientation];
if (UIDeviceOrientationUnknown == curDevOrientation) {
// UIDevice isn't firing orientation notifications yet… go look at the status bar
curDevOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
}
if (UIDeviceOrientationIsValidInterfaceOrientation(curDevOrientation)) {
for (NSNumber *orient in self.viewController.supportedOrientations) {
if ([orient intValue] == curDevOrientation) {
forceStartupRotation = NO;
break;
}
}
}
if (forceStartupRotation) {
NSLog(#"supportedOrientations: %#", self.viewController.supportedOrientations);
// The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait)
UIInterfaceOrientation newOrient = [[self.viewController.supportedOrientations objectAtIndex:0] intValue];
NSLog(#"AppDelegate forcing status bar to: %d from: %d", newOrient, curDevOrientation);
[[UIApplication sharedApplication] setStatusBarOrientation:newOrient];
}
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
return YES;
}
// this happens while we are running ( in the background, or from within our own app )
// only valid if ios-cordova-childbrowser-Info.plist specifies a protocol to handle
- (BOOL) application:(UIApplication*)application handleOpenURL:(NSURL*)url
{
if (!url) {
return NO;
}
// calls into javascript global function 'handleOpenURL'
NSString* jsString = [NSString stringWithFormat:#"handleOpenURL(\"%#\");", url];
[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];
// all plugins will get the notification, and their handlers will be called
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
return YES;
}
- (void) dealloc
{
[super dealloc];
}
- (void)setOrientation:(NSMutableArray *)arguments
{
NSLog(#"setting orientation");
MainViewController *vc = self.viewController;
[vc setDevideDirection:2];
//self.viewController.supportedOrientations = arguments;
//self.viewController.supportedOrientations = arguments;
}
#end

Avoid audio to continue in another view

I have an app where I play an audio-file on launch in the View Controller. I also have a button that switches to my second view. My problem is that the audio continues to play even after I have switched view. Here's my code for ViewController.m:
#import <AVFoundation/AVFoundation.h>
#interface ViewController ()
#end
#implementation ViewController
//When I go to this view, I want the audio to stop
- (IBAction)SwitchView:(id)sender {
SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:second animated:YES completion:NULL];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"home_sound"
ofType:#"mp3"]];
NSError *error;
homeaudioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:url
error:&error];
if (error)
{
NSLog(#"Error in audioPlayer: %#",
[error localizedDescription]);
} else {
homeaudioPlayer.delegate = self;
[homeaudioPlayer setNumberOfLoops: -1];
[homeaudioPlayer prepareToPlay];
}
[homeaudioPlayer play];
}
#end
How can I do this?
Thanks.
update your SwitchView code-
- (IBAction)SwitchView:(id)sender {
[homeaudioPlayer stop];
SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:second animated:YES completion:NULL];
}
Simply add [homeaudioPlayer stop]; to your switchView method. This should stop all sound that the player is playing.

Send Audio by Email

How could I get the audio from phone and get it to share via email?
Will it available?
Can we share it simply like music at application?
Your question could have been better, you should show what you've tried, your specific problem, your actual results and your expected result.
Having said that, this sounded like a nice challenge.. so the answer follows.
I'm not sure if you wanted to get the music from the iPod or the app bundle so I implemented the iPod version as (in my opinion), it's more complex.
SSCCE:
main.m
#import "AppDelegate.h"
int main(int argc, char * argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
AppDelegate.h
#import UIKit;
#import MessageUI;
#import MediaPlayer;
#interface AppDelegate : UIResponder <UIApplicationDelegate, MFMailComposeViewControllerDelegate, MPMediaPickerControllerDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
AppDelegate.m
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
UIViewController *controller = [[UIViewController alloc] init];
_window.rootViewController = controller;
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES;
mediaPicker.prompt = #"Select songs to play";
[_window.rootViewController presentViewController:mediaPicker animated:YES completion:^{
}];
return YES;
}
-(void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSLog(#"Result:%d", result);
[controller dismissViewControllerAnimated:YES completion:nil];
}
-(void) mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
[mediaPicker dismissViewControllerAnimated:YES completion:^{
NSArray *recipents = #[#"a#b.com"];
MFMailComposeViewController *messageController = [[MFMailComposeViewController alloc] init];
messageController.mailComposeDelegate = self;
[messageController setToRecipients:recipents];
[messageController setMessageBody:#"Here is a music track" isHTML:NO];
[messageController setSubject:#"Music"];
NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
for (MPMediaItem *item in mediaItemCollection.items)
{
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
AVAsset *asset = [AVAsset assetWithURL:url];
NSArray *presets = [AVAssetExportSession exportPresetsCompatibleWithAsset:asset];
AVAssetExportSession *session = [AVAssetExportSession exportSessionWithAsset:asset presetName:presets[0]];
session.outputURL = [[tmpDirURL URLByAppendingPathComponent:#"item"] URLByAppendingPathExtension:#"m4a"];
session.outputFileType = [session supportedFileTypes][0];
[session exportAsynchronouslyWithCompletionHandler:^{
NSData *data = [NSData dataWithContentsOfURL:session.outputURL];
[messageController addAttachmentData:data mimeType:#"audio/mp4" fileName:#"musicAttachment.m4a"];
}];
}
[_window.rootViewController presentViewController:messageController animated:YES completion:^{
}];
}];
}
-(void) mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker
{
}
#end

Stop background music

I have this app that has several view controllers. In the app delegate, I set it so that as soon as the app finishes launching, the background music starts. However, on another view controller, I have this button that plays this video. My problem is that when I play the movie, the background audio overlaps with the movie. My question is, how do I stop the music when I play the movie and play the music after the movie ends.
Here is my app_delegate.h:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#interface App_Delegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#end
Here is my App_Delegate.m
#import "App_Delegate.h"
#import "RootViewController.h"
#implementation App_Delegate
#synthesize window;
#synthesize navigationController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
{NSString* soundFilePath = [[NSBundle mainBundle] pathForResource:#"beethoven_sym_5_i" ofType:#"mp3"];
NSURL* soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer* player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops=-1;
[player play];
}
// Override point for customization after application launch.
// Set the navigation controller as the window's root view controller and display.
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[navigationController release];
[window release];
[super dealloc];
}
#end
My MovieViewController.h:
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
#interface MovieViewController : UIViewController {
IBOutlet UIScrollView *sesamescroller;
}
- (IBAction)playsesamemovie:(id)sender;
#end
Finally, my MovieViewController.m
#import "MovieViewController.h"
#interface MovieViewController ()
#end
#implementation MovieViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
- (void)viewDidUnload
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)playsesamemovie:(id)sender {
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"How to make Sesame chicken" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
- (void)dealloc {
[sesamescroller release];
[super dealloc];
}
#end
The code you show has a local variable pointing to the player object. To control the player, other code needs to be able to find it. Like this:
In App_Delegate.h:
#property (strong) AVAudioPlayer *player;
in App_Delegate.m: (where did this underbar come from? Most unconventional!)
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
self.player.numberOfLoops=-1;
[self.player play];
Then, wherever you want to control it:
[((App_Delegate *)([UIApplication sharedApplication].delegate)).player pause];
// ...
[((App_Delegate *)([UIApplication sharedApplication].delegate)).player play];
set scalling mode to your player
for Paused :
[moviePlayerController setScalingMode:MPMoviePlaybackStatePaused];
for Stopped:
[moviePlayerController setScalingMode:MPMoviePlaybackStateStopped];
If possible on iOS, you can use scriptable feature to send message to mute. I did this sometime back for Mac OS X where I used to control iTunes from another app.
First add start to songs in application delegate
.h application delegate
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
#class ViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate,AVAudioPlayerDelegate>
{
AVAudioPlayer *myAudioPlayer;
NSDictionary *config;
NSMutableArray *ARRAY;
}
-(void)stop;
#property(retain,nonatomic) NSDictionary *config;
#property (nonatomic, retain) AVAudioPlayer *myAudioPlayer;
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ViewController *viewController;
#end
.m application delegate
#implementation AppDelegate
{
AVAudioPlayer* audioPlayer;
}
#synthesize myAudioPlayer;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
audioPlayer.delegate = self;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
audioPlayer.numberOfLoops = 1;
audioPlayer.delegate=self;
[audioPlayer play];
}
-(void)stop
{
[audioPlayer stop];
}
-(void)star
{
[audioPlayer play];
}
when use required start and stop background music in application
directly call this method -start and -stop
..it really work

Resources