SSLTrack::getLengthInSeconds PHP Method

getLengthInSeconds() public method

Pass SSLTrack::TRY_HARD if you would like the file length to be guessed from the file itself, if possible, and don't mind that this is possibly an expensive operation.
public getLengthInSeconds ( $flags )
$flags
    public function getLengthInSeconds($flags = 0)
    {
        if ($flags & self::TRY_HARD) {
            $this->setLengthIfUnknown();
        }
        if (preg_match('/^(\\d+):(\\d+)/', $this->getLength(), $matches)) {
            return $matches[1] * 60 + $matches[2];
        }
        return 0;
    }

Usage Example

 public function notifyScrobble(SSLTrack $track)
 {
     $length = $track->getLengthInSeconds(SSLTrack::TRY_HARD);
     if ($length == 0) {
         // Perhaps this entry was added manually.
         L::level(L::WARNING) && L::log(L::WARNING, __CLASS__, 'Could not guess length. Last.fm will silently ignore the scrobble.', array());
     }
     try {
         $this->scrobbler->add($track->getArtist(), $track->getTitle(), $track->getAlbum(), $length, $track->getStartTime());
         L::level(L::DEBUG) && L::log(L::DEBUG, __CLASS__, 'Sending %d scrobble(s) to Last.fm', array($this->scrobbler->getQueueSize()));
         $this->scrobbler->submit();
         // TODO: caching if scrobbling's down whilst playing.
     } catch (Exception $e) {
         L::level(L::WARNING) && L::log(L::WARNING, __CLASS__, 'Could not send %d scrobble(s) to Last.fm: %s', array($this->scrobbler->getQueueSize(), $e->getMessage()));
     }
 }
All Usage Examples Of SSLTrack::getLengthInSeconds