Пример #1
0
 public static function play($music)
 {
     if (self::$paused == 0) {
         music::$status = "loading";
         $seconds = $music == self::$playing ? 0.3 : 2.5;
         Simulator::$nextPlayStarted = Simulator::schedule($seconds);
     } else {
         music::$status = "playing";
         Simulator::$nextPlayComplete = Simulator::schedule(self::$paused);
         self::$paused = 0;
     }
 }
Пример #2
0
 public function search($params)
 {
     $query = Music::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['defaultOrder' => ['Id' => SORT_ASC, 'name' => SORT_ASC]]);
     $query->andFilterWhere([music::tableName() . '.status' => '0']);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['Id' => $this->Id, 'createdOn' => $this->createdOn, 'status' => $this->status, 'updatedOn' => $this->updatedOn, 'createdBy' => $this->createdBy, 'updatedBy' => $this->updatedBy]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'IP', $this->IP])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'searchAlias', $this->searchAlias]);
     return $dataProvider;
 }
Пример #3
0
        $this->offset = $offset;
        $this->number = $number;
    }
    protected function get_content()
    {
        $url = 'http://s.music.163.com/search/get/?s=' . urlencode($this->name) . '&type=1&limit=' . $this->number . '&offset=' . $this->offset;
        //        $url='http://so.1ting.com/all.do?q='.urlencode($this->name);
        if (!function_exists('file_get_contents')) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
            $file_content = curl_exec($ch);
            curl_close($ch);
        } else {
            $file_content = file_get_contents($url);
        }
        return $file_content;
    }
    public function get_music_info()
    {
        $data = $this->get_content();
        $data = json_decode(json_encode(json_decode($data)), true);
        foreach ($data['result']['songs'] as $v) {
            $list[] = ['name' => $v['name'], 'artist' => $v['artists'][0]['name'], 'album' => $v['album']['name'], 'img' => $v['album']['picUrl'], 'audio' => $v['audio']];
        }
        echo json_encode($list);
    }
}
$demo = new music('青春修炼手册', 5);
$demo->get_music_info();