- if (!empty($selected)) {
- $attachments['visual'][] = $video[$selected];
- unset($video[$selected]);
- foreach ($video as $element) {
- $attachments['additional'][] = $element;
+
+ if (!empty($heights)) {
+ ksort($heights);
+ foreach ($heights as $height => $url) {
+ if (empty($selected) || $height <= 480) {
+ $selected = $url;
+ }
+ }
+
+ if (!empty($selected)) {
+ $attachments['visual'][] = $video[$selected];
+ unset($video[$selected]);
+ foreach ($video as $element) {
+ $attachments['additional'][] = $element;
+ }