Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a audioplayer application like pandora app?
    text
    copied!<p>I am created an application which play multiple audio files from locally. Audio files are long. Audio player has following options for the user</p> <ul> <li>Forward,</li> <li>Rewind,</li> <li>Next Track,</li> <li>Previous Track,</li> </ul> <p>I am planning to use AvAudioPlayer so that i can play an audio with long time. When i am changing the audio file ie pressing next track audio. The audioplayer instance is not getting released. This problem is appearing some times only. Please help me..!! I am help less.. </p> <p>Next Track Button IBAction Method</p> <pre><code>- (IBAction) nextTrackPressed { [audioPlay stopAudio]; if (audioPlay) { audioPlay = nil; [audioPlay release]; } appDelegate.trackSelected += 1; [self intiNewAudioFile]; [self play]; } Initializing audio file through below method -(void) intiNewAudioFile { NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init]; NSString *filePath = [[NSString alloc] init]; trackObject = [appDelegate.trackDetailArray objectAtIndex:appDelegate.trackSelected]; NSLog(@"%@",trackObject.trackName); // Get the file path to the song to play. filePath = [[NSBundle mainBundle] pathForResource:trackObject.trackName ofType:@"mp3"]; // Convert the file path to a URL. NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath]; if (audioPlay) { audioPlay = nil; [audioPlay release]; } audioPlay = [[AudioPlayerClass alloc] init]; [audioPlay initAudioWithUrl:fileURL]; [filePath release]; [fileURL release]; [subPool release]; } </code></pre> <p>AudioPlayerClass Implementation</p> <pre><code>#import "AudioPlayerClass.h" @implementation AudioPlayerClass - (void) initAudioWithUrl: (NSURL *) url { curAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [curAudioPlayer setDelegate:self]; [curAudioPlayer prepareToPlay]; } - (void) playAudio { [curAudioPlayer play]; } - (void) pauseAudio { [curAudioPlayer pause]; } - (void) stopAudio { [curAudioPlayer stop]; } - (BOOL) isAudioPlaying { return curAudioPlayer.playing; } - (void) setAudiowithCurrentTime:(NSInteger) time { curAudioPlayer.currentTime = time; } - (NSInteger) getAudioFileDuration { return curAudioPlayer.duration; } - (NSInteger) getAudioCurrentTime { return curAudioPlayer.currentTime; } - (void) releasePlayer { [curAudioPlayer release]; } - (void)dealloc { [curAudioPlayer release]; [super dealloc]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload