forked from decarbonization/PlayerKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PKAudioPlayer.h
136 lines (99 loc) · 5.84 KB
/
PKAudioPlayer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* PKAudioPlayer.h
* PlayerKit
*
* Created by Peter MacWhinnie on 10/16/10.
* Copyright 2010 __MyCompanyName__. All rights reserved.
*
*/
#ifndef PKAudioPlayer_h
#define PKAudioPlayer_h 1
#import <CoreFoundation/CoreFoundation.h>
#pragma mark Constants
///The notification posted when an audio player encounters an error during playback.
///The notification is always posted on the main thread. The userInfo dictionary of
///the notification contains one key, CFSTR("Error"), which contains a CFErrorRef
///describing the problem. PKAudioPlayer has stopped playback when this notification
///is posted.
PK_EXTERN CFStringRef const PKAudioPlayerDidEncounterErrorNotification;
///The notification posted when an audio player finishes playing an audio file.
///The notification is always posted on the main thread. The userInfo dictionary
///of the notification contains one key, CFSTR("DidFinish"), which contains a CFBoolean
///indicating whether or not the audio file was played all the way through.
PK_EXTERN CFStringRef const PKAudioPlayerDidFinishPlayingNotification;
///The notification posted when an audio player has changed output devices.
PK_EXTERN CFStringRef const PKAudioPlayerDidChangeOutputDeviceNotification;
///The notification posted when an audio player discovers that another
///PlayerKit-powered application is playing music on the host computer.
PK_EXTERN CFStringRef const PKAudioPlayerDidEncounterOtherPlayerNotification;
///The different possible output destinations that can be returned by PKAudioPlayer.
typedef enum PKAudioPlayerOutputDestination {
///PKAudioPlayer does not know where it is sending audio.
kPKAudioPlayerOutputDestinationUnknown = 0,
///PKAudioPlayer is sending audio to headphones connected to the computer.
kPKAudioPlayerOutputDestinationHeadphones = 'hdpn',
///PKAudioPlayer is sending audio to the computer's internal speakers.
kPKAudioPlayerOutputDestinationInternalSpeakers = 'ispk',
} PKAudioPlayerOutputDestination;
#pragma mark -
#pragma mark Lifecycle
///Initialize the audio player's internal state.
/// \param outError An object encapsulating a description of any errors that occurred. May be null. Must be freed by caller.
/// \result true if initialization succeeds; false otherwise.
PK_EXTERN Boolean PKAudioPlayerInit(CFErrorRef *outError);
///Teardown the audio player's internal state.
/// \param outError An object encapsulating a description of any errors that occurred. May be null. Must be freed by caller.
/// \result true if the teardown succeeds; false otherwise.
PK_EXTERN Boolean PKAudioPlayerTeardown(CFErrorRef *outError);
#pragma mark -
#pragma mark Controlling Playback
///Set the source file of the audio player.
/// \param location The location of the audio file to play.
/// \param outError An object encapsulating a description of any errors that occurred. May be null. Must be freed by caller.
/// \result true if the file located at the passed in URL was loaded successfully; false otherwise.
PK_EXTERN Boolean PKAudioPlayerSetURL(CFURLRef location, CFErrorRef *outError);
///Returns the URL indicating the location of the source file of the audio player.
PK_EXTERN CFURLRef PKAudioPlayerCopyURL();
#pragma mark -
///Start playback in the audio player.
/// \param outError An object encapsulating a description of any errors that occurred. May be null. Must be freed by caller.
/// \result true if playback could be started; false otherwise.
PK_EXTERN Boolean PKAudioPlayerPlay(CFErrorRef *outError);
///Stop playback in the audio player.
/// \param postNotification If true then the audio player will post a PKAudioPlayerDidFinishPlayingNotification.
/// \param outError An object encapsulating a description of any errors that occurred. May be null. Must be freed by caller.
/// \result true if playback could be stopped; false otherwise.
PK_EXTERN Boolean PKAudioPlayerStop(Boolean postNotification, CFErrorRef *outError);
///Returns a Boolean indicating whether or not the audio player is currently playing something.
PK_EXTERN Boolean PKAudioPlayerIsPlaying();
#pragma mark -
///Pause playback in the audio player.
/// \param outError An object encapsulating a description of any errors that occurred. May be null. Must be freed by caller.
/// \result true if playback could be paused; false otherwise.
PK_EXTERN Boolean PKAudioPlayerPause(CFErrorRef *outError);
///Resume playback after being paused in the audio player.
/// \param outError An object encapsulating a description of any errors that occurred. May be null. Must be freed by caller.
/// \result true if playback could be resumed; false otherwise.
PK_EXTERN Boolean PKAudioPlayerResume(CFErrorRef *outError);
///Returns a Boolean indicating whether or not the audio player is currently paused.
PK_EXTERN Boolean PKAudioPlayerIsPaused();
#pragma mark -
#pragma mark Properties
///Set the volume level of the audio player. The scale is {0.0, 1.0}, the default value is 1.0.
PK_EXTERN Boolean PKAudioPlayerSetVolume(Float32 volume, CFErrorRef *outError);
///Returns the volume level of the audio player. The scale is {0.0, 1.0}.
PK_EXTERN Float32 PKAudioPlayerGetVolume();
///Returns the average CPU usage of the audio player.
PK_EXTERN Float32 PKAudioPlayerGetAverageCPUUsage();
#pragma mark -
///The duration of the song the audio player is currently playing.
PK_EXTERN CFTimeInterval PKAudioPlayerGetDuration();
#pragma mark -
///Sets the location of playback in the song the audio player is playing.
PK_EXTERN Boolean PKAudioPlayerSetCurrentTime(CFTimeInterval currentTime, CFErrorRef *outError);
///Returns the current location of playback in the song the audio player is playing.
PK_EXTERN CFTimeInterval PKAudioPlayerGetCurrentTime();
#pragma mark -
///Returns the physical destination of audio sent from PKAudioPlayer to the user.
PK_EXTERN PKAudioPlayerOutputDestination PKAudioPlayerGetAudioOutputDestination(CFErrorRef *outError);
#endif /* PKAudioPlayer_h */