Skip to content

Commit 65058b7

Browse files
committed
Update
1 parent 92ce69b commit 65058b7

File tree

141 files changed

+36229
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+36229
-4
lines changed

AudioUnitPlayerDemo/AudioUnitPlayerDemo.xcodeproj/project.pbxproj

Lines changed: 552 additions & 0 deletions
Large diffs are not rendered by default.

AudioUnitPlayerDemo/AudioUnitPlayerDemo/Base.lproj/Main.storyboard

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" systemVersion="17A277" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
59
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
610
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
711
</dependencies>
812
<scenes>
913
<!--View Controller-->
1014
<scene sceneID="tne-QT-ifu">
1115
<objects>
12-
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
16+
<viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController">
1317
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
1418
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1519
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
20+
<subviews>
21+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Mob-zZ-SU0">
22+
<rect key="frame" x="60" y="227" width="37" height="36"/>
23+
<color key="backgroundColor" red="0.93725490199999995" green="0.4941176471" blue="0.4941176471" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
24+
<fontDescription key="fontDescription" type="system" pointSize="20"/>
25+
<state key="normal" title="play"/>
26+
<connections>
27+
<action selector="playBtnClick:" destination="BYZ-38-t0r" eventType="touchUpInside" id="nnB-jC-1Dv"/>
28+
</connections>
29+
</button>
30+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="PF7-u8-cTJ">
31+
<rect key="frame" x="166" y="227" width="46" height="30"/>
32+
<color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
33+
<constraints>
34+
<constraint firstAttribute="height" constant="30" id="8X3-Ab-eZB"/>
35+
<constraint firstAttribute="width" constant="46" id="kZR-6P-KfL"/>
36+
</constraints>
37+
<fontDescription key="fontDescription" type="system" pointSize="20"/>
38+
<state key="normal" title="stop"/>
39+
<connections>
40+
<action selector="stopBtnClick:" destination="BYZ-38-t0r" eventType="touchUpInside" id="h8X-lz-kHf"/>
41+
</connections>
42+
</button>
43+
</subviews>
1644
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
45+
<constraints>
46+
<constraint firstItem="PF7-u8-cTJ" firstAttribute="leading" secondItem="Mob-zZ-SU0" secondAttribute="trailing" constant="69" id="0l4-hB-uPo"/>
47+
<constraint firstItem="Mob-zZ-SU0" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="60" id="oRG-Lg-z7x"/>
48+
<constraint firstItem="PF7-u8-cTJ" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="207" id="sr7-G6-a2o"/>
49+
<constraint firstItem="Mob-zZ-SU0" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="207" id="vgk-o8-4KJ"/>
50+
</constraints>
1751
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
1852
</view>
1953
</viewController>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// AVAudioSession+ST_RouteUtils.h
3+
// 01AudioPlayerMe
4+
//
5+
// Created by codew on 2018/7/28.
6+
// Copyright © 2018年 codew. All rights reserved.
7+
//
8+
9+
#import <AVFoundation/AVFoundation.h>
10+
11+
@interface AVAudioSession (ST_RouteUtils)
12+
13+
- (BOOL)usingBlueTooth;
14+
15+
- (BOOL)usingWiredMicrophone;
16+
17+
- (BOOL)shouldShowEarphoneAlert;
18+
19+
@end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// AVAudioSession+ST_RouteUtils.m
3+
// 01AudioPlayerMe
4+
//
5+
// Created by codew on 2018/7/28.
6+
// Copyright © 2018年 codew. All rights reserved.
7+
//
8+
9+
#import "AVAudioSession+ST_RouteUtils.h"
10+
11+
@implementation AVAudioSession (ST_RouteUtils)
12+
13+
14+
- (BOOL)usingBlueTooth {
15+
NSArray *inputs = self.currentRoute.inputs;
16+
NSArray *blueToothInputRoutes = @[AVAudioSessionPortBluetoothHFP];
17+
for (AVAudioSessionPortDescription *description in inputs) {
18+
if ([blueToothInputRoutes containsObject:description.portType]) {
19+
return YES;
20+
}
21+
}
22+
23+
NSArray *outputs = self.currentRoute.outputs;
24+
NSArray *blueToothOutputRoutes = @[AVAudioSessionPortBluetoothHFP, AVAudioSessionPortBluetoothA2DP, AVAudioSessionPortBluetoothLE];
25+
for (AVAudioSessionPortDescription *description in outputs) {
26+
if ([blueToothOutputRoutes containsObject:description.portType]) {
27+
return YES;
28+
}
29+
}
30+
31+
return NO;
32+
}
33+
34+
- (BOOL)usingWiredMicrophone {
35+
NSArray *inputs = self.currentRoute.inputs;
36+
NSArray *headSetInputRoutes = @[AVAudioSessionPortHeadsetMic];
37+
for (AVAudioSessionPortDescription *description in inputs) {
38+
if ([headSetInputRoutes containsObject:description.portType]) {
39+
return YES;
40+
}
41+
}
42+
43+
NSArray *outputs = self.currentRoute.outputs;
44+
NSArray *headSetOutputRoutes = @[AVAudioSessionPortHeadphones, AVAudioSessionPortUSBAudio];
45+
for (AVAudioSessionPortDescription *description in outputs) {
46+
if ([headSetOutputRoutes containsObject:description.portType]) {
47+
return YES;
48+
}
49+
}
50+
return NO;
51+
}
52+
53+
- (BOOL)shouldShowEarphoneAlert
54+
{
55+
// 用户如果没有带耳机,则应该提出提示,目前采用保守策略,即尽量减少alert弹出,所以,我们认为只要不是用手机内置的听筒或者喇叭作为声音外放的,都认为用户带了耳机
56+
NSArray *outputs = self.currentRoute.outputs;
57+
NSArray *headSetOutputRoutes = @[AVAudioSessionPortBuiltInReceiver, AVAudioSessionPortBuiltInSpeaker];
58+
for (AVAudioSessionPortDescription *description in outputs) {
59+
if ([headSetOutputRoutes containsObject:description.portType]) {
60+
return YES;
61+
}
62+
}
63+
return NO;
64+
}
65+
66+
@end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// CommonUtil.h
3+
// video_player
4+
//
5+
// Created by apple on 16/8/25.
6+
// Copyright © 2016年 xiaokai.zhan. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface CommonUtil : NSObject
12+
13+
+(NSString *)bundlePath:(NSString *)fileName;
14+
15+
+(NSString *)documentsPath:(NSString *)fileName;
16+
17+
@end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// CommonUtil.m
3+
// video_player
4+
//
5+
// Created by apple on 16/8/25.
6+
// Copyright © 2016年 xiaokai.zhan. All rights reserved.
7+
//
8+
9+
#import "CommonUtil.h"
10+
11+
@implementation CommonUtil
12+
13+
+(NSString *)bundlePath:(NSString *)fileName {
14+
return [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:fileName];
15+
}
16+
17+
+(NSString *)documentsPath:(NSString *)fileName {
18+
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
19+
NSString *documentsDirectory = [paths objectAtIndex:0];
20+
return [documentsDirectory stringByAppendingPathComponent:fileName];
21+
}
22+
23+
@end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// ST_AudioOutput.h
3+
// 01AudioPlayerMe
4+
//
5+
// Created by codew on 2018/7/26.
6+
// Copyright © 2018年 codew. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
// 数据填充, 喂数据
12+
@protocol FillDataOutputDelegate <NSObject>
13+
14+
@optional
15+
- (NSInteger) fillAudioData:(SInt16*) sampleBuffer numFrames:(NSInteger)frameNum numChannels:(NSInteger)channels;
16+
17+
18+
@end
19+
20+
@interface ST_AudioOutput : NSObject
21+
22+
23+
@property (nonatomic, assign) Float64 sampleRate;
24+
@property (nonatomic, assign) Float64 channels;
25+
26+
- (id)initWithChannels:(NSInteger)channels
27+
sampleRate:(NSInteger)sampleRate
28+
bytesPerSample:(NSInteger)bytePerSample
29+
fileDataDelegate:(id<FillDataOutputDelegate>)fileDataDelegate;
30+
31+
- (BOOL)play;
32+
- (void)stop;
33+
34+
35+
@end

0 commit comments

Comments
 (0)