forked from BigShow1949/BigShow1949
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
1,209 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+32.7 KB
(150%)
BigShow1949.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/JS/JS_MessageHandler/HLAudioPlayer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// HLAudioPlayer.h | ||
// 音效播放器 | ||
// | ||
// Created by Harvey on 14/6/2. | ||
// Copyright © 2014年 Haley. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <AVFoundation/AVFoundation.h> | ||
|
||
@interface HLAudioPlayer : NSObject | ||
|
||
+ (AVAudioPlayer *)playMusic:(NSString *)fileName; | ||
|
||
+ (void)pauseMusic:(NSString *)fileName; | ||
|
||
+ (void)stopMusic:(NSString *)fileName; | ||
|
||
|
||
+ (void)playSound:(NSString *)soundName; | ||
|
||
+ (void)disposeSound:(NSString *)soundName; | ||
|
||
@end |
134 changes: 134 additions & 0 deletions
134
BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/JS/JS_MessageHandler/HLAudioPlayer.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// | ||
// HLAudioPlayer.m | ||
// 音效播放器 | ||
// | ||
// Created by Harvey on 14/6/2. | ||
// Copyright © 2014年 Haley. All rights reserved. | ||
// | ||
|
||
#import "HLAudioPlayer.h" | ||
|
||
@implementation HLAudioPlayer | ||
|
||
+ (void)initialize | ||
{ | ||
// 音频会话 | ||
AVAudioSession *session = [AVAudioSession sharedInstance]; | ||
// 设置会话类型 | ||
[session setCategory:AVAudioSessionCategoryPlayback error:nil]; | ||
// 激活会话 | ||
[session setActive:YES error:nil]; | ||
} | ||
|
||
// 音效Id | ||
static NSMutableDictionary *_soundIDs; | ||
|
||
+ (NSMutableDictionary *)soundIDs | ||
{ | ||
if (!_soundIDs) { | ||
_soundIDs = [NSMutableDictionary dictionary]; | ||
} | ||
return _soundIDs; | ||
} | ||
|
||
|
||
// 所有的播放器 | ||
static NSMutableDictionary *_musicPlayers; | ||
+ (NSMutableDictionary *)musicPlayers | ||
{ | ||
if (!_musicPlayers) { | ||
_musicPlayers = [NSMutableDictionary dictionary]; | ||
} | ||
return _musicPlayers; | ||
} | ||
|
||
+ (AVAudioPlayer *)playMusic:(NSString *)fileName | ||
{ | ||
if (!fileName) { | ||
return nil; | ||
} | ||
|
||
AVAudioPlayer *player = [self musicPlayers][fileName]; | ||
if (!player) { | ||
NSURL *URL = [[NSBundle mainBundle] URLForResource:fileName withExtension:nil]; | ||
if (!URL) { | ||
return nil; | ||
} | ||
player = [[AVAudioPlayer alloc] initWithContentsOfURL:URL error:nil]; | ||
|
||
if (![player prepareToPlay]) { | ||
return nil; | ||
} | ||
|
||
[self musicPlayers][fileName] = player; | ||
} | ||
|
||
if (!player.isPlaying) { | ||
[player play]; | ||
} | ||
|
||
return player; | ||
} | ||
|
||
+ (void)pauseMusic:(NSString *)fileName | ||
{ | ||
if (!fileName) { | ||
return; | ||
} | ||
|
||
AVAudioPlayer *player = [self musicPlayers][fileName]; | ||
|
||
[player pause]; | ||
} | ||
|
||
+ (void)stopMusic:(NSString *)fileName | ||
{ | ||
if (!fileName) { | ||
return; | ||
} | ||
|
||
AVAudioPlayer *player = [self musicPlayers][fileName]; | ||
|
||
[player stop]; | ||
|
||
[[self musicPlayers] removeObjectForKey:fileName]; | ||
} | ||
|
||
+ (void)playSound:(NSString *)soundName | ||
{ | ||
if (!soundName) { | ||
return; | ||
} | ||
|
||
SystemSoundID soundID = [[self soundIDs][soundName] unsignedIntValue]; | ||
|
||
if (!soundID) { | ||
NSURL *URL = [[NSBundle mainBundle] URLForResource:soundName withExtension:nil]; | ||
if (!URL) { | ||
return; | ||
} | ||
|
||
AudioServicesCreateSystemSoundID((__bridge CFURLRef _Nonnull)(URL), &soundID); | ||
|
||
[self soundIDs][soundName] = @(soundID); | ||
} | ||
|
||
AudioServicesPlaySystemSound(soundID); | ||
} | ||
|
||
+ (void)disposeSound:(NSString *)soundName | ||
{ | ||
if (!soundName) { | ||
return; | ||
} | ||
|
||
SystemSoundID soundID = [[self soundIDs][soundName] unsignedIntValue]; | ||
|
||
if (soundID) { | ||
AudioServicesDisposeSystemSoundID(soundID); | ||
|
||
[[self soundIDs] removeObjectForKey:soundName]; | ||
} | ||
} | ||
|
||
@end |
Oops, something went wrong.