@@ -4,38 +4,42 @@ var AV = require('av');
44try {
55 var OggDemuxer = require ( 'ogg.js' ) ;
66} catch ( e ) { } ;
7- if ( ! OggDemuxer ) return ;
8-
9- OggDemuxer . plugins . push ( {
10- magic : "\177FLAC" ,
11-
12- init : function ( ) {
13- this . list = new AV . BufferList ( ) ;
14- this . stream = new AV . Stream ( this . list ) ;
15- } ,
16-
17- readHeaders : function ( packet ) {
18- var stream = this . stream ;
19- this . list . append ( new AV . Buffer ( packet ) ) ;
20-
21- stream . advance ( 5 ) ; // magic
22- if ( stream . readUInt8 ( ) != 1 )
23- throw new Error ( 'Unsupported FLAC version' ) ;
24-
25- stream . advance ( 3 ) ;
26- if ( stream . peekString ( 0 , 4 ) != 'fLaC' )
27- throw new Error ( 'Not flac' ) ;
28-
29- this . flac = AV . Demuxer . find ( stream . peekSingleBuffer ( 0 , stream . remainingBytes ( ) ) ) ;
30- if ( ! this . flac )
31- throw new Error ( 'Flac demuxer not found' ) ;
32-
33- this . flac . prototype . readChunk . call ( this ) ;
34- return true ;
35- } ,
36-
37- readPacket : function ( packet ) {
38- this . list . append ( new AV . Buffer ( packet ) ) ;
39- this . flac . prototype . readChunk . call ( this ) ;
40- }
41- } ) ;
7+
8+ // return calling outside a function will be not proper.
9+ // if (!OggDemuxer) return;
10+
11+ if ( OggDemuxer ) {
12+ OggDemuxer . plugins . push ( {
13+ magic : "\177FLAC" ,
14+
15+ init : function ( ) {
16+ this . list = new AV . BufferList ( ) ;
17+ this . stream = new AV . Stream ( this . list ) ;
18+ } ,
19+
20+ readHeaders : function ( packet ) {
21+ var stream = this . stream ;
22+ this . list . append ( new AV . Buffer ( packet ) ) ;
23+
24+ stream . advance ( 5 ) ; // magic
25+ if ( stream . readUInt8 ( ) != 1 )
26+ throw new Error ( 'Unsupported FLAC version' ) ;
27+
28+ stream . advance ( 3 ) ;
29+ if ( stream . peekString ( 0 , 4 ) != 'fLaC' )
30+ throw new Error ( 'Not flac' ) ;
31+
32+ this . flac = AV . Demuxer . find ( stream . peekSingleBuffer ( 0 , stream . remainingBytes ( ) ) ) ;
33+ if ( ! this . flac )
34+ throw new Error ( 'Flac demuxer not found' ) ;
35+
36+ this . flac . prototype . readChunk . call ( this ) ;
37+ return true ;
38+ } ,
39+
40+ readPacket : function ( packet ) {
41+ this . list . append ( new AV . Buffer ( packet ) ) ;
42+ this . flac . prototype . readChunk . call ( this ) ;
43+ }
44+ } ) ;
45+ }
0 commit comments