·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> AudioStreamer使用之快速点击下/上一首按钮,音频会重复的问题解决。

AudioStreamer使用之快速点击下/上一首按钮,音频会重复的问题解决。

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

针对此问题,我的做法是在AudioStreamer.h文件新加入一个属性

@PRoperty (nonatomic,strong) NSURL *musicUrl;

和一个单例方法:

+(id)sharedStreamer;

同时在AudioStreamer.m文件中实现单例方法和musicURL的set方法

+(id)sharedStreamer{

    static AudioStreamer *streamer = nil;

    static dispatch_once_t tocken;

    dispatch_once(&tocken, ^{

        streamer = [[AudioStreamer alloc] init];

    });

    return streamer;

}

 

-(void)setMusicUrl:(NSURL *)musicUrl{

    url = musicUrl;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruptionChangeToState:) name:ASAudiosessionInterruptionOccuredNotification object:nil];

}

 

这样后在创建streamer对象的时候变可以像下面那样做:

streamer = [AudioStreamer sharedStreamer];

[streamer stop];

streamer.musicUrl = url;

[streamer start];

 

那么问题解决。。晚安!