/** * Constructs the class with given parameters and reads object related data * from the Flac bitstream. * * @param HausDesign_Io_Reader $reader The reader object. */ public function __construct($reader) { $this->_reader = $reader; $this->_last = ($tmp = $this->_reader->readUInt8()) >> 7 & 0x1; $this->_type = $tmp & 0x7f; $this->_size = $this->_reader->readUInt24BE(); }
/** * Constructs the class with given filename. * * @param string|resource|HausDesign_Io_Reader $filename The path to the file, * file descriptor of an opened file, or a {@link HausDesign_Io_Reader} instance. * @throws HausDesign_Io_Exception if an error occur in stream handling. * @throws HausDesign_Media_Flac_Exception if an error occurs in vorbis bitstream reading. */ public function __construct($filename) { if ($filename instanceof HausDesign_Io_Reader) { $this->_reader =& $filename; } else { $this->_filename = $filename; require_once 'HausDesign/Io/FileReader.php'; try { $this->_reader = new HausDesign_Io_FileReader($filename); } catch (HausDesign_Io_Exception $e) { $this->_reader = null; require_once 'HausDesign/Media/Flac/Exception.php'; throw new HausDesign_Media_Flac_Exception($e->getMessage()); } } $capturePattern = $this->_reader->read(4); if ($capturePattern != 'fLaC') { require_once 'HausDesign/Media/Flac/Exception.php'; throw new HausDesign_Media_Flac_Exception('Not a valid FLAC bitstream'); } while (true) { $offset = $this->_reader->getOffset(); $last = ($tmp = $this->_reader->readUInt8()) >> 7 & 0x1; $type = $tmp & 0x7f; $size = $this->_reader->readUInt24BE(); $this->_reader->setOffset($offset); switch ($type) { case self::STREAMINFO: // 0 require_once 'HausDesign/Media/Flac/MetadataBlock/Streaminfo.php'; $this->_metadataBlocks[] = new HausDesign_Media_Flac_MetadataBlock_Streaminfo($this->_reader); break; case self::PADDING: // 1 require_once 'HausDesign/Media/Flac/MetadataBlock/Padding.php'; $this->_metadataBlocks[] = new HausDesign_Media_Flac_MetadataBlock_Padding($this->_reader); break; case self::APPLICATION: // 2 require_once 'HausDesign/Media/Flac/MetadataBlock/Application.php'; $this->_metadataBlocks[] = new HausDesign_Media_Flac_MetadataBlock_Application($this->_reader); break; case self::SEEKTABLE: // 3 require_once 'HausDesign/Media/Flac/MetadataBlock/Seektable.php'; $this->_metadataBlocks[] = new HausDesign_Media_Flac_MetadataBlock_Seektable($this->_reader); break; case self::VORBIS_COMMENT: // 4 require_once 'HausDesign/Media/Flac/MetadataBlock/VorbisComment.php'; $this->_metadataBlocks[] = new HausDesign_Media_Flac_MetadataBlock_VorbisComment($this->_reader); break; case self::CUESHEET: // 5 require_once 'HausDesign/Media/Flac/MetadataBlock/Cuesheet.php'; $this->_metadataBlocks[] = new HausDesign_Media_Flac_MetadataBlock_Cuesheet($this->_reader); break; case self::PICTURE: // 6 require_once 'HausDesign/Media/Flac/MetadataBlock/Picture.php'; $this->_metadataBlocks[] = new HausDesign_Media_Flac_MetadataBlock_Picture($this->_reader); break; default: // break intentionally omitted } $this->_reader->setOffset($offset + 4 + $size); // Jump off the loop if we reached the end of metadata blocks if ($last === 1) { break; } } }