Exemplo n.º 1
0
 /**
  * scan a folder for music
  * @param OC_EventSource eventSource (optional)
  * @return int the number of songs found
  */
 public static function scanCollection($eventSource = null)
 {
     $music = OC_Files::searchByMime('audio');
     $ogg = OC_Files::searchByMime('application/ogg');
     $music = array_merge($music, $ogg);
     $eventSource->send('count', count($music));
     $songs = 0;
     foreach ($music as $file) {
         self::scanFile($file);
         $songs++;
         if ($eventSource) {
             $eventSource->send('scanned', array('file' => $file, 'count' => $songs));
         }
     }
     if ($eventSource) {
         $eventSource->send('done', $songs);
     }
     return $songs;
 }
Exemplo n.º 2
0
                    $song['album'] = OC_MEDIA_COLLECTION::getAlbumName($song['song_album']);
                    OCP\JSON::encodedPrint($song);
                }
            }
            break;
        case 'play':
            @ob_end_clean();
            $ftype = OC_Filesystem::getMimeType($arguments['path']);
            if (substr($ftype, 0, 5) != 'audio' and $ftype != 'application/ogg') {
                echo 'Not an audio file';
                exit;
            }
            $songId = OC_MEDIA_COLLECTION::getSongByPath($arguments['path']);
            OC_MEDIA_COLLECTION::registerPlay($songId);
            header('Content-Type:' . $ftype);
            OCP\Response::enableCaching(3600 * 24);
            // 24 hour
            header('Accept-Ranges: bytes');
            header('Content-Length: ' . OC_Filesystem::filesize($arguments['path']));
            $mtime = OC_Filesystem::filemtime($arguments['path']);
            OCP\Response::setLastModifiedHeader($mtime);
            OC_Filesystem::readfile($arguments['path']);
            exit;
        case 'find_music':
            $music = OC_Files::searchByMime('audio');
            $ogg = OC_Files::searchByMime('application/ogg');
            $music = array_merge($music, $ogg);
            OCP\JSON::encodedPrint($music);
            exit;
    }
}