コード例 #1
0
ファイル: Reader.php プロジェクト: pthurmond/fit-php
 /**
  * Every .FIT file starts of with a file header which is parsed here.
  * @return string[] The file header
  */
 protected function readFileHeader()
 {
     $this->file_header = array('header_size' => $this->reader->readUInt8(), 'protocol_version' => $this->reader->readUInt8(), 'profile_version' => $this->reader->readUInt16(), 'data_size' => $this->reader->readUInt32LE(), 'data_type' => $this->reader->readString8(4));
     //when not found, the profile will be the default
     $this->profile->setProtocolAndProfile($this->file_header['protocol_version'], $this->file_header['profile_version']);
     if ($this->file_header['header_size'] > 12) {
         $this->file_header += array('crc' => $this->reader->readUInt16LE());
     }
     //make sure we are at start of first record
     $this->reader->setOffset($this->file_header['header_size']);
     return $this->file_header;
 }
コード例 #2
0
ファイル: Id3v1.php プロジェクト: adam-fonseca/RuneUI
 /**
  * Writes the possibly altered ID3v1 tag back to the file where it was read.
  * If the class was constructed without a file name, one can be provided
  * here as an argument. Regardless, the write operation will override
  * previous tag information, if found.
  *
  * @param string $filename The optional path to the file.
  * @throws Zend_Media_Id3_Exception if there is no file to write the tag to
  */
 public function write($filename = null)
 {
     if ($filename === null && ($filename = $this->_filename) === null) {
         require_once 'Zend/Media/Id3/Exception.php';
         throw new Zend_Media_Id3_Exception('No file given to write the tag to');
     }
     require_once 'Zend/Io/FileWriter.php';
     try {
         $writer = new Zend_Io_FileWriter($filename);
         $offset = $writer->getSize();
         if ($this->_reader !== null) {
             $offset = -128;
         } else {
             $reader = new Zend_Io_Reader($writer->getFileDescriptor());
             $reader->setOffset(-128);
             if ($reader->read(3) == 'TAG') {
                 $offset = -128;
             }
         }
         $writer->setOffset($offset);
         $writer->writeString8('TAG')->writeString8(substr($this->_title, 0, 30), 30)->writeString8(substr($this->_artist, 0, 30), 30)->writeString8(substr($this->_album, 0, 30), 30)->writeString8(substr($this->_year, 0, 4), 4);
         if ($this->_track) {
             $writer->writeString8(substr($this->_comment, 0, 28), 28)->writeInt8(0)->writeInt8($this->_track);
         } else {
             $writer->writeString8(substr($this->_comment, 0, 30), 30);
         }
         $writer->writeInt8($this->_genre);
         $writer->flush();
     } catch (Zend_Io_Exception $e) {
         require_once 'Zend/Media/Id3/Exception.php';
         throw new Zend_Media_Id3_Exception($e->getMessage());
     }
     $this->_filename = $filename;
 }
コード例 #3
0
ファイル: Flac.php プロジェクト: adam-fonseca/RuneUI
 /**
  * Constructs the class with given filename.
  *
  * @param string|resource|Zend_Io_Reader $filename The path to the file,
  *  file descriptor of an opened file, or a {@link Zend_Io_Reader} instance.
  * @throws Zend_Io_Exception if an error occur in stream handling.
  * @throws Zend_Media_Flac_Exception if an error occurs in vorbis bitstream reading.
  */
 public function __construct($filename)
 {
     if ($filename instanceof Zend_Io_Reader) {
         $this->_reader =& $filename;
     } else {
         $this->_filename = $filename;
         require_once 'Zend/Io/FileReader.php';
         try {
             $this->_reader = new Zend_Io_FileReader($filename);
         } catch (Zend_Io_Exception $e) {
             $this->_reader = null;
             require_once 'Zend/Media/Flac/Exception.php';
             throw new Zend_Media_Flac_Exception($e->getMessage());
         }
     }
     $capturePattern = $this->_reader->read(4);
     if ($capturePattern != 'fLaC') {
         require_once 'Zend/Media/Flac/Exception.php';
         throw new Zend_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 'Zend/Media/Flac/MetadataBlock/Streaminfo.php';
                 $this->_metadataBlocks[] = new Zend_Media_Flac_MetadataBlock_Streaminfo($this->_reader);
                 break;
             case self::PADDING:
                 // 1
                 require_once 'Zend/Media/Flac/MetadataBlock/Padding.php';
                 $this->_metadataBlocks[] = new Zend_Media_Flac_MetadataBlock_Padding($this->_reader);
                 break;
             case self::APPLICATION:
                 // 2
                 require_once 'Zend/Media/Flac/MetadataBlock/Application.php';
                 $this->_metadataBlocks[] = new Zend_Media_Flac_MetadataBlock_Application($this->_reader);
                 break;
             case self::SEEKTABLE:
                 // 3
                 require_once 'Zend/Media/Flac/MetadataBlock/Seektable.php';
                 $this->_metadataBlocks[] = new Zend_Media_Flac_MetadataBlock_Seektable($this->_reader);
                 break;
             case self::VORBIS_COMMENT:
                 // 4
                 require_once 'Zend/Media/Flac/MetadataBlock/VorbisComment.php';
                 $this->_metadataBlocks[] = new Zend_Media_Flac_MetadataBlock_VorbisComment($this->_reader);
                 break;
             case self::CUESHEET:
                 // 5
                 require_once 'Zend/Media/Flac/MetadataBlock/Cuesheet.php';
                 $this->_metadataBlocks[] = new Zend_Media_Flac_MetadataBlock_Cuesheet($this->_reader);
                 break;
             case self::PICTURE:
                 // 6
                 require_once 'Zend/Media/Flac/MetadataBlock/Picture.php';
                 $this->_metadataBlocks[] = new Zend_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;
         }
     }
 }
コード例 #4
0
ファイル: Reader.php プロジェクト: adam-fonseca/RuneUI
 /**
  * Overwrite the method to set the point of operation within the Ogg bitstream.
  *
  * @param integer $offset The new point of operation.
  * @return void
  * @throws Zend_Io_Exception if an I/O error occurs
  */
 public function setOffset($offset)
 {
     $streamSize = 0;
     for ($i = 0, $pageCount = count($this->_pages); $i < $pageCount; $i++) {
         if ($streamSize + $this->_pages[$i]['page']->getPageSize() >= $offset) {
             $this->_currentPageNumber = $i;
             $this->_currentPagePosition = $offset - $streamSize;
             parent::setOffset($this->_pages[$i]['offset'] + $this->_pages[$i]['page']->getHeaderSize() + $this->_currentPagePosition);
             break;
         }
         $streamSize += $this->_pages[$i]['page']->getPageSize();
     }
 }