zoukankan      html  css  js  c++  java
  • 音乐模块的播放功能

    利用  AVAudioPlayer 来播放音乐 :
     
    - 声明对象
     
    #import <AVKit/AVKit.h>
    #import <AVFoundation/AVFoundation.h>
    @property (nonatomic, strong) AVAudioPlayer *avAudioPlayer;
     
    - 播放函数
     
    NSURL *url = [[NSURLalloc] initWithString:[AppUtilurlEncodeToURLString:urlStr]];
    NSData *audioData = [NSDatadataWithContentsOfURL:url];
    _avAudioPlayer = [[AVAudioPlayeralloc] initWithData:audioData error:nil];
    [_avAudioPlayerplay];
    _avAudioPlayer.delegate = self;
    _stringUrlAudio = urlStr;
     
    <附加函数>
     
    + (NSString *)urlEncodeToURLString:(NSString *)urlString
    {
        if (IS_NS_STRING_EMPTY(urlString)) {
            return@"";
        }
        NSString *encodingUrl = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        return encodingUrl;
    }
     
    - 代理函数
     
    - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
    {
        [self.voiceImageViewstopAnimating];
        self.weplayPage.avAudioPlayer = nil;
    }
     
    图标的播放时的动态效果代码如下:
     
    - (UIImageView *)voiceImageView
    {
        if (!_voiceImageView) {
            _voiceImageView = [[UIImageViewalloc] initWithFrame:CGRectMake(14, 0, 12, 12)];
            _voiceImageView.centerY = self.soundImageView.bounds.size.height/2.0;
            _voiceImageView.contentMode = UIViewContentModeScaleAspectFill;
            NSArray *arr = @[@"ic_yiqiwan_details_play1",@"ic_yiqiwan_details_play2",@"ic_yiqiwan_details_play3"];
            [self.soundImageViewaddSubview:_voiceImageView];
           
            NSMutableArray *imageArray = [NSMutableArrayarray];
            for (int i=0;i<arr.count;++i) {
                UIImage *tmpimage = [UIImageimageNamed:arr[i]];
                [imageArray cl_addObject:tmpimage];
            }
            _voiceImageView.animationImages = imageArray;
            _voiceImageView.animationRepeatCount = 0;
            _voiceImageView.animationDuration = 1.5;
            _voiceImageView.image = [UIImageimageNamed:@"ic_yiqiwan_details_play3"];
            //[_voiceImageView startAnimating];
        }
        return_voiceImageView;
    }
     
    动画效果如下:
     
     C9B0CD5C 5C11 4029 B109 D138BC2F41C4 
     
    - OVER
  • 相关阅读:
    输入一个字符串,输出该字符串中字符的所有组合 C#【总结】
    Asp.net的身份验证【转载】
    C#面试基础问题【转载】
    Testing and Checking Refined
    Exploratory Testing 3.0 探索式测试
    博客搬家
    Seven Kinds of Testers - 七种类型的测试
    使用Spring的Property文件存储测试数据 - 初始化
    Protractor 怎样运行
    Protractor-引入Cucumber
  • 原文地址:https://www.cnblogs.com/firstrate/p/7888051.html
Copyright © 2011-2022 走看看