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];

     

    那么问题解决。。晚安!

  • 相关阅读:
    nginx的rewrite指令
    springmvc上传图片《2》
    cors解决跨域
    java8的Streams
    vue基础篇---路由的实现《2》
    vue基础篇---vue组件《2》
    vue基础篇---watch监听
    ES6新特性
    ubuntu tftp 配置
    驱动程序分层分离概念--总线驱动设备模型
  • 原文地址:https://www.cnblogs.com/buakaw/p/ios.html
Copyright © 2011-2022 走看看