zoukankan      html  css  js  c++  java
  • AudioStreamer使用之快速点击下/上一首按钮,音频会重复的问题解决。

    针对此问题,我的做法是在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];

     

    那么问题解决。。晚安!

  • 相关阅读:
    python-day8(正式学习)
    Bug快到碗里来
    python-day7(正式学习)
    python-day6(正式学习)
    python-day5(正式学习)
    python-day4(正式学习)
    Django中间件
    cookie和session
    分页器,form组件的使用
    orm常用字段和数据库优化查询
  • 原文地址:https://www.cnblogs.com/buakaw/p/ios.html
Copyright © 2011-2022 走看看