开发者

AVaudioPlayer regarding song overlapping

开发者 https://www.devze.com 2022-12-29 20:36 出处:网络
I have using AVAudioPl开发者_如何学编程ayer in my app but the problem is that when i play the song from list it will played while before stopping the song i am again goes to song list then select anot

I have using AVAudioPl开发者_如何学编程ayer in my app but the problem is that when i play the song from list it will played while before stopping the song i am again goes to song list then select another song then both song will start playing simultaneously so please tell me the code which will terminate my first song.

I use flag variable for initializing the song file---

fileURL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@" Om Namo" ofType:@"aac"]];
self._player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
if (self._player)
{
_fileName.text = [NSString stringWithFormat: @"%@ (%d ch.)", [[self._player.url relativePath] lastPathComponent], self._player.numberOfChannels, nil];
[self updateViewForPlayerInfo];
[self updateViewForPlayerState];
}

[fileURL release];
break;

Play and push function---

- (void)startPlayback
{

if ([self._player play])
{
//[self stop];
[self updateViewForPlayerState];
self._player.delegate = self;
}
else
NSLog(@"Could not play %@\n", self._player.url);
}

- (void)pausePlayback
{
[self._player pause];
[self updateViewForPlayerState];
}

I also make stop function---

-(void)stop
{
[_player release];
self._player=nil;
}

Please help me . Is correct my stop function. and where i put our stop function or any other solution to fix this problem...


I can think of 3 things :

1) You can make code look like code by putting 4 spaces infront of each line. The reason you've gt no answers so far is probably because your question is almost unreadable ;)

2) In your stop method you might want to try this :

- (void) stop {
    [_player stop];
    self._player = nil;
}

3) Apple highly discourage using an underscore in front of member names. I've never run into problems but I'd rename _player to player.

0

精彩评论

暂无评论...
验证码 换一张
取 消