当前位置: 首页>>代码示例>>PHP>>正文


PHP Stream::check_lock_media方法代码示例

本文整理汇总了PHP中Stream::check_lock_media方法的典型用法代码示例。如果您正苦于以下问题:PHP Stream::check_lock_media方法的具体用法?PHP Stream::check_lock_media怎么用?PHP Stream::check_lock_media使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stream的用法示例。


在下文中一共展示了Stream::check_lock_media方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: debug_event

if ($media->catalog) {
    // Build up the catalog for our current object
    $catalog = Catalog::create_from_id($media->catalog);
    /* If the media is disabled */
    if (!make_bool($media->enabled)) {
        debug_event('Play', "Error: {$media->file} is currently disabled, song skipped", '5');
        // Check to see if this is a democratic playlist, if so remove it completely
        if ($demo_id && isset($democratic)) {
            $democratic->delete_from_oid($oid, $type);
        }
        header('HTTP/1.1 404 File Disabled');
        exit;
    }
    // If we are running in Legalize mode, don't play medias already playing
    if (AmpConfig::get('lock_songs')) {
        if (!Stream::check_lock_media($media->id, $type)) {
            exit;
        }
    }
    $media = $catalog->prepare_media($media);
} else {
    // No catalog, must be song preview or something like that => just redirect to file
    if ($type == "song_preview") {
        $media->stream();
    } else {
        header('Location: ' . $media->file);
        exit;
    }
}
if ($media == null) {
    // Handle democratic removal
开发者ID:ivan801,项目名称:ampache,代码行数:31,代码来源:index.php

示例2: get_chunk

 public function get_chunk()
 {
     $chunk = null;
     if (!$this->is_init) {
         $this->init_channel_songs();
     }
     if ($this->is_init) {
         // Move to next song
         while ($this->media == null && ($this->random || $this->song_pos < count($this->songs))) {
             if ($this->random) {
                 $randsongs = $this->playlist->get_random_items(1);
                 $this->media = new Song($randsongs[0]['object_id']);
             } else {
                 $this->media = new Song($this->songs[$this->song_pos]);
             }
             $this->media->format();
             if ($this->media->catalog) {
                 $catalog = Catalog::create_from_id($this->media->catalog);
                 if (make_bool($this->media->enabled)) {
                     if (AmpConfig::get('lock_songs')) {
                         if (!Stream::check_lock_media($this->media->id, 'song')) {
                             debug_event('channel', 'Media ' . $this->media->id . ' locked, skipped.', '3');
                             $this->media = null;
                         }
                     }
                 }
                 if ($this->media != null) {
                     $this->media = $catalog->prepare_media($this->media);
                     if (!$this->media->file || !Core::is_readable(Core::conv_lc_file($this->media->file))) {
                         debug_event('channel', 'Cannot read media ' . $this->media->id . ' file, skipped.', '3');
                         $this->media = null;
                     } else {
                         $valid_types = $this->media->get_stream_types();
                         if (!in_array('transcode', $valid_types)) {
                             debug_event('channel', 'Missing settings to transcode ' . $this->media->file . ', skipped.', '3');
                             $this->media = null;
                         } else {
                             debug_event('channel', 'Now listening to ' . $this->media->file . '.', '5');
                         }
                     }
                 }
             } else {
                 debug_event('channel', 'Media ' . $this->media->id . ' doesn\'t have catalog, skipped.', '3');
                 $this->media = null;
             }
             $this->song_pos++;
             // Restart from beginning for next song if the channel is 'loop' enabled
             // and load fresh data from database
             if ($this->media != null && $this->song_pos == count($this->songs) && $this->loop) {
                 $this->init_channel_songs();
             }
         }
         if ($this->media != null) {
             // Stream not yet initialized for this media, start it
             if (!$this->transcoder) {
                 $this->transcoder = Stream::start_transcode($this->media, $this->stream_type, $this->bitrate);
                 $this->media_bytes_streamed = 0;
             }
             if (is_resource($this->transcoder['handle'])) {
                 $chunk = fread($this->transcoder['handle'], 4096);
                 $this->media_bytes_streamed += strlen($chunk);
                 // End of file, prepare to move on for next call
                 if (feof($this->transcoder['handle'])) {
                     $this->media->set_played();
                     if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
                         fread($this->transcoder['stderr'], 4096);
                         fclose($this->transcoder['stderr']);
                     }
                     fclose($this->transcoder['handle']);
                     proc_close($this->transcoder['process']);
                     $this->media = null;
                     $this->transcoder = null;
                 }
             } else {
                 $this->media = null;
                 $this->transcoder = null;
             }
             if (!strlen($chunk)) {
                 $chunk = $this->get_chunk();
             }
         }
     }
     return $chunk;
 }
开发者ID:axelsimon,项目名称:ampache,代码行数:84,代码来源:channel.class.php

示例3: get_chunk

 public function get_chunk()
 {
     $chunk = null;
     if (!$this->is_init) {
         $this->init_channel_songs();
     }
     if ($this->is_init) {
         // Move to next song
         while ($this->media == null && ($this->random || $this->song_pos < count($this->songs))) {
             if ($this->random) {
                 $randsongs = $this->playlist->get_random_items(1);
                 $this->media = new Song($randsongs[0]['object_id']);
             } else {
                 $this->media = new Song($this->songs[$this->song_pos]);
             }
             $this->media->format();
             if ($this->media->catalog) {
                 $catalog = Catalog::create_from_id($this->media->catalog);
                 if (make_bool($this->media->enabled)) {
                     if (AmpConfig::get('lock_songs')) {
                         if (!Stream::check_lock_media($this->media->id, 'song')) {
                             debug_event('channel', 'Media ' . $this->media->id . ' locked, skipped.', '3');
                             $this->media = null;
                         }
                     }
                 }
                 if ($this->media != null) {
                     $this->media = $catalog->prepare_media($this->media);
                     if (!$this->media->file || !Core::is_readable(Core::conv_lc_file($this->media->file))) {
                         debug_event('channel', 'Cannot read media ' . $this->media->id . ' file, skipped.', '3');
                         $this->media = null;
                     } else {
                         $valid_types = $this->media->get_stream_types();
                         if (!in_array('transcode', $valid_types)) {
                             debug_event('channel', 'Missing settings to transcode ' . $this->media->file . ', skipped.', '3');
                             $this->media = null;
                         } else {
                             debug_event('channel', 'Now listening to ' . $this->media->file . '.', '5');
                         }
                     }
                 }
             } else {
                 debug_event('channel', 'Media ' . $this->media->id . ' doesn\'t have catalog, skipped.', '3');
                 $this->media = null;
             }
             $this->song_pos++;
             // Restart from beginning for next song if the channel is 'loop' enabled
             // and load fresh data from database
             if ($this->media != null && $this->song_pos == count($this->songs) && $this->loop) {
                 $this->init_channel_songs();
             }
         }
         if ($this->media != null) {
             // Stream not yet initialized for this media, start it
             if (!$this->transcoder) {
                 $options = array('bitrate' => $this->bitrate);
                 $this->transcoder = Stream::start_transcode($this->media, $this->stream_type, null, $options);
                 $this->media_bytes_streamed = 0;
             }
             if (is_resource($this->transcoder['handle'])) {
                 if (ftell($this->transcoder['handle']) == 0) {
                     $this->header_chunk = '';
                 }
                 $chunk = fread($this->transcoder['handle'], $this->chunk_size);
                 $this->media_bytes_streamed += strlen($chunk);
                 if (ftell($this->transcoder['handle']) < 10000 && strtolower($this->stream_type) == "ogg" || $this->header_chunk_remainder) {
                     //debug_event('channel', 'File handle pointer: ' . ftell($this->transcoder['handle']) ,'5');
                     $clchunk = $chunk;
                     if ($this->header_chunk_remainder) {
                         $this->header_chunk .= substr($clchunk, 0, $this->header_chunk_remainder);
                         if (strlen($clchunk) >= $this->header_chunk_remainder) {
                             $clchunk = substr($clchunk, $this->header_chunk_remainder);
                             $this->header_chunk_remainder = 0;
                         } else {
                             $this->header_chunk_remainder = $this->header_chunk_remainder - strlen($clchunk);
                             $clchunk = '';
                         }
                     }
                     // see bin/channel_run.inc for explanation what's happening here
                     while ($this->strtohex(substr($clchunk, 0, 4)) == "4F676753") {
                         $hex = $this->strtohex(substr($clchunk, 0, 27));
                         $ogg_nr_of_segments = hexdec(substr($hex, 26 * 2, 2));
                         if (substr($clchunk, 27 + $ogg_nr_of_segments + 1, 6) == "vorbis" || substr($clchunk, 27 + $ogg_nr_of_segments, 4) == "Opus") {
                             $hex .= $this->strtohex(substr($clchunk, 27, $ogg_nr_of_segments));
                             $ogg_sum_segm_laces = 0;
                             for ($segm = 0; $segm < $ogg_nr_of_segments; $segm++) {
                                 $ogg_sum_segm_laces += hexdec(substr($hex, 27 * 2 + $segm * 2, 2));
                             }
                             $this->header_chunk .= substr($clchunk, 0, 27 + $ogg_nr_of_segments + $ogg_sum_segm_laces);
                             if (strlen($clchunk) < 27 + $ogg_nr_of_segments + $ogg_sum_segm_laces) {
                                 $this->header_chunk_remainder = (int) (27 + $ogg_nr_of_segments + $ogg_sum_segm_laces - strlen($clchunk));
                             }
                             $clchunk = substr($clchunk, 27 + $ogg_nr_of_segments + $ogg_sum_segm_laces);
                         } else {
                             //no more interesting headers
                             $clchunk = '';
                         }
                     }
                 }
                 //debug_event('channel', 'File handle pointer: ' . ftell($this->transcoder['handle']) ,'5');
//.........这里部分代码省略.........
开发者ID:cheese1,项目名称:ampache,代码行数:101,代码来源:channel.class.php

示例4: debug_event

if ($media->catalog) {
    // Build up the catalog for our current object
    $catalog = Catalog::create_from_id($media->catalog);
    /* If the song is disabled */
    if (!make_bool($media->enabled)) {
        debug_event('Play', "Error: {$media->file} is currently disabled, song skipped", '5');
        // Check to see if this is a democratic playlist, if so remove it completely
        if ($demo_id && isset($democratic)) {
            $democratic->delete_from_oid($oid, 'song');
        }
        header('HTTP/1.1 404 File Disabled');
        exit;
    }
    // If we are running in Legalize mode, don't play songs already playing
    if (AmpConfig::get('lock_songs')) {
        if (!Stream::check_lock_media($media->id, get_class($media))) {
            exit;
        }
    }
    $media = $catalog->prepare_media($media);
} else {
    // No catalog, must be song preview or something like that => just redirect to file
    header('Location: ' . $media->file);
    $media = null;
}
if ($media == null) {
    // Handle democratic removal
    if ($demo_id && isset($democratic)) {
        $democratic->delete_from_oid($oid, 'song');
    }
    exit;
开发者ID:PaulCharlton,项目名称:demo-compose-templates,代码行数:31,代码来源:index.php


注:本文中的Stream::check_lock_media方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。