diff --git a/app/controllers/Api/Web/DashboardController.php b/app/controllers/Api/Web/DashboardController.php index e444ee61..4a9936e4 100644 --- a/app/controllers/Api/Web/DashboardController.php +++ b/app/controllers/Api/Web/DashboardController.php @@ -20,7 +20,7 @@ ->explicitFilter() ->published() ->orderBy('published_at', 'desc') - ->take(20); + ->take(30); $recentTracks = []; diff --git a/app/controllers/TracksController.php b/app/controllers/TracksController.php index 2863740a..d89772f0 100644 --- a/app/controllers/TracksController.php +++ b/app/controllers/TracksController.php @@ -66,16 +66,29 @@ return Redirect::action('TracksController@getTrack', [$id, $track->slug]); } - public function getStream($id) { + public function getStream($id, $extension) { $track = Track::find($id); if (!$track || !$track->canView(Auth::user())) App::abort(404); - $format = Track::$Formats['MP3']; + $format = null; + $formatName = null; + + foreach (Track::$Formats as $name => $item) { + if ($item['extension'] == $extension) { + $format = $item; + $formatName = $name; + break; + } + } + + if ($format == null) + App::abort(404); + ResourceLogItem::logItem('track', $id, ResourceLogItem::PLAY, $format['index']); $response = Response::make('', 200); - $filename = $track->getFileFor('MP3'); + $filename = $track->getFileFor($formatName); if (Config::get('app.sendfile')) { $response->header('X-Sendfile', $filename); diff --git a/app/filters.php b/app/filters.php index 0456d3a0..f7af7627 100644 --- a/app/filters.php +++ b/app/filters.php @@ -38,11 +38,11 @@ Log::listen(function($level, $message, $context) use ($profiler) { $profiler->log($level, $message, $context); }); - } - App::error(function($exception) { - return Response::view('errors.404', array(), 404); - }); + App::error(function($exception) { + return Response::view('errors.500', array(), 404); + }); + } App::missing(function($exception) { return Response::view('errors.404', array(), 404); diff --git a/app/models/Entities/Track.php b/app/models/Entities/Track.php index 13a9ae3e..2fab16aa 100644 --- a/app/models/Entities/Track.php +++ b/app/models/Entities/Track.php @@ -8,6 +8,7 @@ use Helpers; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cache; + use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\URL; @@ -54,7 +55,7 @@ } public static function popular($count, $allowExplicit = false) { - $trackIds = Cache::remember('popular_tracks-' . ($allowExplicit ? 'explicit' : 'safe'), 5, function() use ($allowExplicit) { + $trackIds = Cache::remember('popular_tracks' . $count . '-' . ($allowExplicit ? 'explicit' : 'safe'), 5, function() use ($allowExplicit, $count) { $query = static ::published() ->join(DB::raw(' @@ -65,7 +66,7 @@ 'tracks.id', '=', 'ranged_plays.track_id') ->groupBy('id') ->orderBy('plays', 'desc') - ->take(20); + ->take($count); if (!$allowExplicit) $query->whereIsExplicit(false); @@ -197,7 +198,9 @@ 'normal' => $track->getCoverUrl(Image::NORMAL) ], 'streams' => [ - 'mp3' => $track->getStreamUrl('MP3') + 'mp3' => $track->getStreamUrl('MP3'), + 'aac' => (!Config::get('app.debug') || is_file($track->getFileFor('AAC')) ) ? $track->getStreamUrl('AAC') : null, + 'ogg' => ( Config::get('app.debug') || is_file($track->getFileFor('OGG Vorbis'))) ? $track->getStreamUrl('OGG Vorbis') : null ], 'user_data' => $userData, 'permissions' => [ @@ -350,8 +353,8 @@ return $this->cover->getUrl($type); } - public function getStreamUrl() { - return URL::to('/t' . $this->id . '/stream'); + public function getStreamUrl($format = 'MP3') { + return URL::to('/t' . $this->id . '/stream.' . self::$Formats[$format]['extension']); } public function getDirectory() { diff --git a/app/routes.php b/app/routes.php index 0a0ae864..9bcfead5 100644 --- a/app/routes.php +++ b/app/routes.php @@ -23,7 +23,7 @@ Route::get('tracks/{id}-{slug}', 'TracksController@getTrack'); Route::get('t{id}', 'TracksController@getShortlink' ); Route::get('t{id}/embed', 'TracksController@getEmbed' ); - Route::get('t{id}/stream', 'TracksController@getStream' ); + Route::get('t{id}/stream.{extension}', 'TracksController@getStream' ); Route::get('t{id}/dl.{extension}', 'TracksController@getDownload' ); Route::get('albums', 'AlbumsController@getIndex'); diff --git a/public/scripts/app/directives/src-loader.coffee b/public/scripts/app/directives/src-loader.coffee index 1655aa28..b244f90d 100644 --- a/public/scripts/app/directives/src-loader.coffee +++ b/public/scripts/app/directives/src-loader.coffee @@ -1,17 +1,22 @@ angular.module('ponyfm').directive 'pfmSrcLoader', () -> (scope, element, attrs) -> size = attrs.pfmSrcSize || 'normal' - url = attrs.pfmSrcLoader + element.css {opacity: .5} - element.attr 'src', '/images/icons/loading_' + size + '.png' + update = (val) -> + element.attr 'src', '/images/icons/loading_' + size + '.png' - image = element.clone() - image.removeAttr 'pfm-src-loader' - image.removeAttr 'pfm-src-size' + image = element.clone() + image.removeAttr 'pfm-src-loader' + image.removeAttr 'pfm-src-size' - image[0].onload = -> - element.replaceWith image - image.css {opacity: 0} - image.animate {opacity: 1}, 250 + image[0].onload = -> + element.attr 'src', val + element.css {opacity: 0} + element.animate {opacity: 1}, 250 - image[0].src = url \ No newline at end of file + image[0].src = val + + update scope.$eval attrs.pfmSrcLoader + + scope.$watch attrs.pfmSrcLoader, update \ No newline at end of file diff --git a/public/scripts/app/services/player.coffee b/public/scripts/app/services/player.coffee index b231a3ec..31c94fd4 100644 --- a/public/scripts/app/services/player.coffee +++ b/public/scripts/app/services/player.coffee @@ -6,8 +6,18 @@ angular.module('ponyfm').factory('player', [ play = (track) -> self.currentTrack = track $rootScope.$broadcast 'player-starting-track', track + + streams = [] + streams.push track.streams.mp3 + streams.push track.streams.ogg if track.streams.ogg + streams.push track.streams.aac if track.streams.aac + + track.progress = 0 + track.progressSeconds = 0 + track.loadingProgress = 0 + self.currentSound = soundManager.createSound - url: track.streams.mp3, + url: streams, volume: self.volume whileloading: () -> $rootScope.safeApply -> @@ -83,7 +93,8 @@ angular.module('ponyfm').factory('player', [ self.currentSound.stop() if self.currentSound != null self.playlistIndex-- - if self.playlistIndex <= 0 + + if self.playlistIndex < 0 self.playlist.length = 0 self.currentTrack = null self.currentSong = null diff --git a/public/styles/player.less b/public/styles/player.less index 2bb4bf88..46b344d9 100644 --- a/public/styles/player.less +++ b/public/styles/player.less @@ -14,13 +14,39 @@ body.is-logged { float: left; width: 43px; height: 43px; + position: relative; + overflow: hidden; + padding: 1px; img { .img-polaroid(); + .box-shadow(none); + display: block; - width: 100%; + width: 40px; + height: 40px; padding: 1px; } + + .loader { + .transition(top 250ms linear); + + z-index: 1000; + background: rgba(0, 0, 0, .6); + color: #fff; + position: absolute; + top: -50px; + left: 2px; + width: 42px; + height: 42px; + line-height: 43px; + text-align: center; + font-size: 16px; + + &.showing { + top: 2px; + } + } } .inner { @@ -51,7 +77,7 @@ body.is-logged { } .transport { - background: @pfm-light-grey; + background: #aaa; height: 8px; position: relative; cursor: pointer; diff --git a/public/templates/account/albums.html b/public/templates/account/albums.html index d415b844..2fb1cddf 100644 --- a/public/templates/account/albums.html +++ b/public/templates/account/albums.html @@ -12,7 +12,7 @@