Skip to content

Commit ec7bc50

Browse files
Add a sample plugin to demonstrate the mute plugin API.
https://bugs.webkit.org/show_bug.cgi?id=139231 Reviewed by Anders Carlsson. * NetscapeMuteAPIPlugin/AudioPlayer.h: Added. * NetscapeMuteAPIPlugin/AudioPlayer.mm: Added. (-[AudioPlayer initWithURL:]): (-[AudioPlayer dealloc]): (-[AudioPlayer isReadyToPlay]): (-[AudioPlayer isPlaying]): (-[AudioPlayer setPlaying:]): (-[AudioPlayer isMuted]): (-[AudioPlayer setMuted:]): (-[AudioPlayer observeValueForKeyPath:ofObject:change:context:]): * NetscapeMuteAPIPlugin/English.lproj/InfoPlist.strings: Added. * NetscapeMuteAPIPlugin/Info.plist: Added. * NetscapeMuteAPIPlugin/MenuHandler.h: Added. * NetscapeMuteAPIPlugin/MenuHandler.m: Added. (-[MenuHandler _play:]): (-[MenuHandler _pause:]): (-[MenuHandler validateUserInterfaceItem:]): (-[MenuHandler initWithAudioPlayer:]): (-[MenuHandler dealloc]): (-[MenuHandler menu]): * NetscapeMuteAPIPlugin/NetscapeMuteAPIPlugin.xcodeproj/project.pbxproj: Added. * NetscapeMuteAPIPlugin/main.m: Added. (-[PluginObject initWithNPP:audioURL:]): (-[PluginObject dealloc]): (-[PluginObject menuHandler]): (-[PluginObject isPlayingAudio]): (-[PluginObject isMuted]): (-[PluginObject setMuted:]): (-[PluginObject readyStateDidChangeForAudioPlayer:]): (-[PluginObject mutedStateDidChangeForAudioPlayer:]): (-[PluginObject playStateDidChangeForAudioPlayer:]): (-[PluginObject _invalidateDisplayString]): (NP_Initialize): (NP_GetEntryPoints): (NP_Shutdown): (NPP_New): (NPP_Destroy): (NPP_SetWindow): (NPP_NewStream): (NPP_DestroyStream): (NPP_WriteReady): (NPP_Write): (NPP_StreamAsFile): (NPP_Print): (handleDraw): (invalidatePlugin): (handleMouseEvent): (NPP_HandleEvent): (NPP_URLNotify): (NPP_GetValue): (NPP_SetValue): * NetscapeMuteAPIPlugin/test.html: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176785 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent fb77811 commit ec7bc50

File tree

10 files changed

+1105
-0
lines changed

10 files changed

+1105
-0
lines changed

Examples/ChangeLog

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
1+
2014-12-03 Ada Chan <[email protected]>
2+
3+
Add a sample plugin to demonstrate the mute plugin API.
4+
https://bugs.webkit.org/show_bug.cgi?id=139231
5+
6+
Reviewed by Anders Carlsson.
7+
8+
* NetscapeMuteAPIPlugin/AudioPlayer.h: Added.
9+
* NetscapeMuteAPIPlugin/AudioPlayer.mm: Added.
10+
(-[AudioPlayer initWithURL:]):
11+
(-[AudioPlayer dealloc]):
12+
(-[AudioPlayer isReadyToPlay]):
13+
(-[AudioPlayer isPlaying]):
14+
(-[AudioPlayer setPlaying:]):
15+
(-[AudioPlayer isMuted]):
16+
(-[AudioPlayer setMuted:]):
17+
(-[AudioPlayer observeValueForKeyPath:ofObject:change:context:]):
18+
* NetscapeMuteAPIPlugin/English.lproj/InfoPlist.strings: Added.
19+
* NetscapeMuteAPIPlugin/Info.plist: Added.
20+
* NetscapeMuteAPIPlugin/MenuHandler.h: Added.
21+
* NetscapeMuteAPIPlugin/MenuHandler.m: Added.
22+
(-[MenuHandler _play:]):
23+
(-[MenuHandler _pause:]):
24+
(-[MenuHandler validateUserInterfaceItem:]):
25+
(-[MenuHandler initWithAudioPlayer:]):
26+
(-[MenuHandler dealloc]):
27+
(-[MenuHandler menu]):
28+
* NetscapeMuteAPIPlugin/NetscapeMuteAPIPlugin.xcodeproj/project.pbxproj: Added.
29+
* NetscapeMuteAPIPlugin/main.m: Added.
30+
(-[PluginObject initWithNPP:audioURL:]):
31+
(-[PluginObject dealloc]):
32+
(-[PluginObject menuHandler]):
33+
(-[PluginObject isPlayingAudio]):
34+
(-[PluginObject isMuted]):
35+
(-[PluginObject setMuted:]):
36+
(-[PluginObject readyStateDidChangeForAudioPlayer:]):
37+
(-[PluginObject mutedStateDidChangeForAudioPlayer:]):
38+
(-[PluginObject playStateDidChangeForAudioPlayer:]):
39+
(-[PluginObject _invalidateDisplayString]):
40+
(NP_Initialize):
41+
(NP_GetEntryPoints):
42+
(NP_Shutdown):
43+
(NPP_New):
44+
(NPP_Destroy):
45+
(NPP_SetWindow):
46+
(NPP_NewStream):
47+
(NPP_DestroyStream):
48+
(NPP_WriteReady):
49+
(NPP_Write):
50+
(NPP_StreamAsFile):
51+
(NPP_Print):
52+
(handleDraw):
53+
(invalidatePlugin):
54+
(handleMouseEvent):
55+
(NPP_HandleEvent):
56+
(NPP_URLNotify):
57+
(NPP_GetValue):
58+
(NPP_SetValue):
59+
* NetscapeMuteAPIPlugin/test.html: Added.
60+
161
2014-03-14 Maciej Stachowiak <[email protected]>
262

363
Replace "Apple Computer, Inc." with "Apple Inc." in copyright headers
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in
3+
consideration of your agreement to the following terms, and your use, installation,
4+
modification or redistribution of this Apple software constitutes acceptance of these
5+
terms. If you do not agree with these terms, please do not use, install, modify or
6+
redistribute this Apple software.
7+
8+
In consideration of your agreement to abide by the following terms, and subject to these
9+
terms, Apple grants you a personal, non-exclusive license, under Apple’s copyrights in
10+
this original Apple software (the "Apple Software"), to use, reproduce, modify and
11+
redistribute the Apple Software, with or without modifications, in source and/or binary
12+
forms; provided that if you redistribute the Apple Software in its entirety and without
13+
modifications, you must retain this notice and the following text and disclaimers in all
14+
such redistributions of the Apple Software. Neither the name, trademarks, service marks
15+
or logos of Apple Inc. may be used to endorse or promote products derived from
16+
the Apple Software without specific prior written permission from Apple. Except as expressly
17+
stated in this notice, no other rights or licenses, express or implied, are granted by Apple
18+
herein, including but not limited to any patent rights that may be infringed by your
19+
derivative works or by other works in which the Apple Software may be incorporated.
20+
21+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES,
22+
EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
23+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS
24+
USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
25+
26+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL
27+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28+
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE,
29+
REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND
30+
WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR
31+
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
#import <WebKit/npfunctions.h>
35+
36+
@class AVPlayer;
37+
@class AVPlayerItem;
38+
@class AudioPlayer;
39+
40+
@protocol AudioPlayerDelegate <NSObject>
41+
42+
- (void)readyStateDidChangeForAudioPlayer:(AudioPlayer *)audioPlayer;
43+
- (void)mutedStateDidChangeForAudioPlayer:(AudioPlayer *)audioPlayer;
44+
- (void)playStateDidChangeForAudioPlayer:(AudioPlayer *)audioPlayer;
45+
46+
@end
47+
48+
@interface AudioPlayer : NSObject {
49+
BOOL _playing;
50+
AVPlayer *_audioPlayer;
51+
AVPlayerItem *_playerItem;
52+
id<AudioPlayerDelegate> _audioPlayerDelegate;
53+
}
54+
55+
- (instancetype)initWithURL:(NSURL *)url;
56+
57+
@property (nonatomic, weak) id<AudioPlayerDelegate> audioPlayerDelegate;
58+
@property (nonatomic, readonly, getter=isReadyToPlay) BOOL readyToPlay;
59+
@property (nonatomic, getter=isPlaying) BOOL playing;
60+
@property (nonatomic, getter=isMuted) BOOL muted;
61+
62+
@end
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in
3+
consideration of your agreement to the following terms, and your use, installation,
4+
modification or redistribution of this Apple software constitutes acceptance of these
5+
terms. If you do not agree with these terms, please do not use, install, modify or
6+
redistribute this Apple software.
7+
8+
In consideration of your agreement to abide by the following terms, and subject to these
9+
terms, Apple grants you a personal, non-exclusive license, under Apple’s copyrights in
10+
this original Apple software (the "Apple Software"), to use, reproduce, modify and
11+
redistribute the Apple Software, with or without modifications, in source and/or binary
12+
forms; provided that if you redistribute the Apple Software in its entirety and without
13+
modifications, you must retain this notice and the following text and disclaimers in all
14+
such redistributions of the Apple Software. Neither the name, trademarks, service marks
15+
or logos of Apple Inc. may be used to endorse or promote products derived from
16+
the Apple Software without specific prior written permission from Apple. Except as expressly
17+
stated in this notice, no other rights or licenses, express or implied, are granted by Apple
18+
herein, including but not limited to any patent rights that may be infringed by your
19+
derivative works or by other works in which the Apple Software may be incorporated.
20+
21+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES,
22+
EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
23+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS
24+
USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
25+
26+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL
27+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28+
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE,
29+
REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND
30+
WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR
31+
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
#import "AudioPlayer.h"
35+
36+
#import <AVFoundation/AVFoundation.h>
37+
38+
static void *itemStatusKVOContext = &itemStatusKVOContext;
39+
40+
@implementation AudioPlayer
41+
42+
@synthesize audioPlayerDelegate=_audioPlayerDelegate;
43+
44+
- (instancetype)initWithURL:(NSURL *)url
45+
{
46+
if (!url.absoluteString.length)
47+
return nil;
48+
49+
if (!(self = [super init]))
50+
return nil;
51+
52+
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
53+
_playerItem = [[AVPlayerItem alloc] initWithAsset:avAsset];
54+
[_playerItem addObserver:self forKeyPath:@"status" options:0 context:itemStatusKVOContext];
55+
_audioPlayer = [[AVPlayer alloc] initWithPlayerItem:_playerItem];
56+
57+
return self;
58+
}
59+
60+
- (void)dealloc
61+
{
62+
[_playerItem removeObserver:self forKeyPath:@"status"];
63+
[_audioPlayer release];
64+
[_playerItem release];
65+
[super dealloc];
66+
}
67+
68+
- (BOOL)isReadyToPlay
69+
{
70+
return _audioPlayer.currentItem.status == AVPlayerItemStatusReadyToPlay;
71+
}
72+
73+
- (BOOL)isPlaying
74+
{
75+
return _playing;
76+
}
77+
78+
- (void)setPlaying:(BOOL)playing
79+
{
80+
if (_playing == playing)
81+
return;
82+
83+
if (playing && !self.isReadyToPlay)
84+
return;
85+
86+
_playing = playing;
87+
88+
if (_playing)
89+
[_audioPlayer play];
90+
else
91+
[_audioPlayer pause];
92+
93+
[_audioPlayerDelegate playStateDidChangeForAudioPlayer:self];
94+
}
95+
96+
- (BOOL)isMuted
97+
{
98+
return _audioPlayer.isMuted;
99+
}
100+
101+
- (void)setMuted:(BOOL)muted
102+
{
103+
if (self.isMuted == muted)
104+
return;
105+
106+
_audioPlayer.muted = muted;
107+
[_audioPlayerDelegate mutedStateDidChangeForAudioPlayer:self];
108+
}
109+
110+
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
111+
112+
if (context == &itemStatusKVOContext) {
113+
dispatch_async(dispatch_get_main_queue(), ^{ [_audioPlayerDelegate readyStateDidChangeForAudioPlayer:self]; });
114+
return;
115+
}
116+
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
117+
}
118+
@end
Binary file not shown.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleExecutable</key>
8+
<string>NetscapeMuteAPIPlugin</string>
9+
<key>CFBundleIconFile</key>
10+
<string></string>
11+
<key>CFBundleIdentifier</key>
12+
<string>com.apple.netscapemuteapiplugin</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundlePackageType</key>
16+
<string>BRPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>1.0</string>
23+
<key>WebPluginDescription</key>
24+
<string>Simple Netscape plug-in that uses the Mute API</string>
25+
<key>WebPluginMIMETypes</key>
26+
<dict>
27+
<key>test/x-netscape-mute-api-plugin</key>
28+
<dict>
29+
<key>WebPluginTypeDescription</key>
30+
<string>Netscape Cocoa Plug-in</string>
31+
</dict>
32+
</dict>
33+
<key>WebPluginName</key>
34+
<string>Netscape Mute API Plug-in</string>
35+
</dict>
36+
</plist>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in
3+
consideration of your agreement to the following terms, and your use, installation,
4+
modification or redistribution of this Apple software constitutes acceptance of these
5+
terms. If you do not agree with these terms, please do not use, install, modify or
6+
redistribute this Apple software.
7+
8+
In consideration of your agreement to abide by the following terms, and subject to these
9+
terms, Apple grants you a personal, non-exclusive license, under Apple’s copyrights in
10+
this original Apple software (the "Apple Software"), to use, reproduce, modify and
11+
redistribute the Apple Software, with or without modifications, in source and/or binary
12+
forms; provided that if you redistribute the Apple Software in its entirety and without
13+
modifications, you must retain this notice and the following text and disclaimers in all
14+
such redistributions of the Apple Software. Neither the name, trademarks, service marks
15+
or logos of Apple Inc. may be used to endorse or promote products derived from
16+
the Apple Software without specific prior written permission from Apple. Except as expressly
17+
stated in this notice, no other rights or licenses, express or implied, are granted by Apple
18+
herein, including but not limited to any patent rights that may be infringed by your
19+
derivative works or by other works in which the Apple Software may be incorporated.
20+
21+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES,
22+
EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
23+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS
24+
USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
25+
26+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL
27+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28+
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE,
29+
REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND
30+
WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR
31+
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
#import <Cocoa/Cocoa.h>
35+
36+
@class AudioPlayer;
37+
38+
@interface MenuHandler : NSObject {
39+
NSMenu *_menu;
40+
AudioPlayer *_audioPlayer;
41+
}
42+
43+
- (id)initWithAudioPlayer:(AudioPlayer *)audioPlayer;
44+
- (NSMenu *)menu;
45+
46+
@end

0 commit comments

Comments
 (0)