Example #1
0
    // get the params
    $playlist = Music::decode($request->param('playlist'));
    // get the list of songs
    $list = Playlist::getSongs($playlist);
    // walk the array and construct URLs
    // The encoded URL value is actually "artist name|album title". The artist
    // name is included to ensure that albums with the same name are not
    // conflated and the pipe character is a delimiter
    array_walk($list, function (&$v, $k) use($playlist) {
        $v = array('name' => $v['Title'], 'url' => '/playlist/' . Music::encode($playlist) . '/song/' . Music::encode($v['file']));
    });
    // build the "previous" link data
    $previous = array('path' => '/playlist', 'text' => 'Playlists');
    // build the shuffle link
    $shuffle = '/playlist/' . Music::encode($playlist) . '/song/shuffle';
    return ListPage::render($playlist, $previous, $shuffle, false, $list);
});
//		playlist/1/song/2 	- load all songs for playlist=1, start playing song=2, go to nowplaying
//
$klein->respond('GET', '/playlist/[:playlist]/song/[:song]', function ($request, $response) {
    // get the params
    $playlist = Music::decode($request->param('playlist'));
    $song = $request->param('song');
    $song = $song == 'shuffle' ? 'shuffle' : Music::decode($song);
    // clear the playlist
    Music::send('clear');
    // get the list of songs
    $songs = Playlist::getSongs($playlist);
    // load the playlist with the requested songs (and figure out the current
    // song position)
    $pos = 0;
Example #2
0
    // get the artist & album values
    list($artist, $album) = explode('|', Music::decode($request->param('album')));
    // get the list of songs
    $list = Album::getSongs($artist, $album);
    // walk the array and construct URLs
    // The encoded URL value is actually "artist name|album title". The artist
    // name is included to ensure that albums with the same name are not
    // conflated and the pipe character is a delimiter
    array_walk($list, function (&$v, $k) use($artist, $album) {
        $v = array('name' => $v['Title'], 'url' => '/album/' . Music::encode($artist . '|' . $album) . '/song/' . Music::encode($v['file']));
    });
    // build the "previous" link data
    $previous = array('path' => '/album', 'text' => 'Albums');
    // build the shuffle link
    $shuffle = '/album/' . Music::encode($artist . '|' . $album) . '/song/shuffle';
    return ListPage::render($album, $previous, $shuffle, false, $list);
});
//		album/1/song/2	- load all songs for album=1, play song=2, go to nowplaying
//
$klein->respond('GET', '/album/[:album]/song/[:song]', function ($request, $response) {
    // get the parameters
    // get the artist & album values
    list($artist, $album) = explode('|', Music::decode($request->param('album')));
    $song = $request->param('song');
    $song = $song == 'shuffle' ? 'shuffle' : Music::decode($song);
    // clear the playlist
    Music::send('clear');
    // get the list of songs
    $songs = Album::getSongs($artist, $album);
    // load the playlist with the requested songs (and figure out the current
    // song position)
Example #3
0
    // conflated and the pipe character is a delimiter
    array_walk($list, function (&$v, $k) {
        $v = array('name' => $v['Title'], 'url' => '/song/' . Music::encode($v['file']));
    });
    $list = array_filter($list, function ($v) {
        return $v['name'] ? true : false;
    });
    usort($list, function ($a, $b) {
        if (array_key_exists('name', $a) && array_key_exists('name', $b)) {
            return $a['name'] < $b['name'] ? -1 : 1;
        }
        return 0;
    });
    // build the shuffle link
    $shuffle = '/song/shuffle';
    return ListPage::render('Songs', null, $shuffle, false, $list);
});
//		song/1 	- load ALL songs, play song=1, go to nowplaying
//
$klein->respond('GET', '/song/[:song]', function ($request, $response) {
    // get parameter
    $song = $request->param('song');
    $song = $song == 'shuffle' ? 'shuffle' : Music::decode($song);
    // clear the playlist
    Music::send('clear');
    // get the list of songs
    $songs = Song::getList();
    // load the playlist with the requested songs (and figure out the current
    // song position)
    $pos = 0;
    for ($i = 0; $i < count($songs); $i++) {