New UI
This commit is contained in:
parent
fbd5e8bb61
commit
3f3818efb7
270 changed files with 7441 additions and 6502 deletions
|
@ -0,0 +1,59 @@
|
|||
package code.name.monkey.retromusic.cast;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.google.android.gms.cast.MediaInfo;
|
||||
import com.google.android.gms.cast.MediaMetadata;
|
||||
import com.google.android.gms.cast.framework.CastSession;
|
||||
import com.google.android.gms.cast.framework.media.RemoteMediaClient;
|
||||
import com.google.android.gms.common.images.WebImage;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import code.name.monkey.retromusic.Constants;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.retromusic.util.RetroUtil;
|
||||
|
||||
/**
|
||||
* Created by naman on 2/12/17.
|
||||
*/
|
||||
|
||||
public class CastHelper {
|
||||
|
||||
public static void startCasting(CastSession castSession, Song song) {
|
||||
|
||||
String ipAddress = RetroUtil.getIPAddress(true);
|
||||
URL baseUrl;
|
||||
try {
|
||||
baseUrl = new URL("http", ipAddress, Constants.CAST_SERVER_PORT, "");
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
String songUrl = baseUrl.toString() + "/song?id=" + song.id;
|
||||
String albumArtUrl = baseUrl.toString() + "/albumart?id=" + song.albumId;
|
||||
|
||||
MediaMetadata musicMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
|
||||
|
||||
musicMetadata.putString(MediaMetadata.KEY_TITLE, song.title);
|
||||
musicMetadata.putString(MediaMetadata.KEY_ARTIST, song.artistName);
|
||||
musicMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE, song.albumName);
|
||||
musicMetadata.putInt(MediaMetadata.KEY_TRACK_NUMBER, song.trackNumber);
|
||||
musicMetadata.addImage(new WebImage(Uri.parse(albumArtUrl)));
|
||||
|
||||
try {
|
||||
MediaInfo mediaInfo = new MediaInfo.Builder(songUrl)
|
||||
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
|
||||
.setContentType("audio/mpeg")
|
||||
.setMetadata(musicMetadata)
|
||||
.setStreamDuration(song.duration)
|
||||
.build();
|
||||
RemoteMediaClient remoteMediaClient = castSession.getRemoteMediaClient();
|
||||
remoteMediaClient.load(mediaInfo, true, 0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package code.name.monkey.retromusic.cast;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.android.gms.cast.framework.CastOptions;
|
||||
import com.google.android.gms.cast.framework.OptionsProvider;
|
||||
import com.google.android.gms.cast.framework.SessionProvider;
|
||||
import com.google.android.gms.cast.framework.media.CastMediaOptions;
|
||||
import com.google.android.gms.cast.framework.media.MediaIntentReceiver;
|
||||
import com.google.android.gms.cast.framework.media.NotificationOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import code.name.monkey.retromusic.R;
|
||||
|
||||
public class CastOptionsProvider implements OptionsProvider {
|
||||
@Override
|
||||
public CastOptions getCastOptions(Context context) {
|
||||
List<String> buttonActions = new ArrayList<>();
|
||||
buttonActions.add(MediaIntentReceiver.ACTION_TOGGLE_PLAYBACK);
|
||||
buttonActions.add(MediaIntentReceiver.ACTION_STOP_CASTING);
|
||||
int[] compatButtonActionsIndicies = new int[]{ 0, 1 };
|
||||
|
||||
NotificationOptions notificationOptions = new NotificationOptions.Builder()
|
||||
.setActions(buttonActions, compatButtonActionsIndicies)
|
||||
.setTargetActivityClassName(ExpandedControlsActivity.class.getName())
|
||||
.build();
|
||||
|
||||
CastMediaOptions mediaOptions = new CastMediaOptions.Builder()
|
||||
.setNotificationOptions(notificationOptions)
|
||||
.setExpandedControllerActivityClassName(ExpandedControlsActivity.class.getName())
|
||||
.build();
|
||||
|
||||
return new CastOptions.Builder()
|
||||
.setReceiverApplicationId(context.getString(R.string.cast_app_id))
|
||||
.setCastMediaOptions(mediaOptions)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SessionProvider> getAdditionalSessionProviders(Context context) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package code.name.monkey.retromusic.cast;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
|
||||
import com.google.android.gms.cast.framework.CastButtonFactory;
|
||||
import com.google.android.gms.cast.framework.media.widget.ExpandedControllerActivity;
|
||||
|
||||
import code.name.monkey.retromusic.R;
|
||||
|
||||
|
||||
public class ExpandedControlsActivity extends ExpandedControllerActivity {
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
getMenuInflater().inflate(R.menu.menu_expanded_controller, menu);
|
||||
CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package code.name.monkey.retromusic.cast;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import code.name.monkey.retromusic.Constants;
|
||||
import code.name.monkey.retromusic.util.RetroUtil;
|
||||
import fi.iki.elonen.NanoHTTPD;
|
||||
|
||||
public class WebServer extends NanoHTTPD {
|
||||
|
||||
private Context context;
|
||||
private Uri songUri, albumArtUri;
|
||||
|
||||
public WebServer(Context context) {
|
||||
super(Constants.CAST_SERVER_PORT);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response serve(String uri, Method method,
|
||||
Map<String, String> header,
|
||||
Map<String, String> parameters,
|
||||
Map<String, String> files) {
|
||||
if (uri.contains("albumart")) {
|
||||
//serve the picture
|
||||
|
||||
String albumId = parameters.get("id");
|
||||
this.albumArtUri = RetroUtil.getAlbumArtUri(Long.parseLong(albumId));
|
||||
|
||||
if (albumArtUri != null) {
|
||||
String mediasend = "image/jpg";
|
||||
InputStream fisAlbumArt = null;
|
||||
try {
|
||||
fisAlbumArt = context.getContentResolver().openInputStream(albumArtUri);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Response.Status st = Response.Status.OK;
|
||||
|
||||
//serve the song
|
||||
return newChunkedResponse(st, mediasend, fisAlbumArt);
|
||||
}
|
||||
|
||||
} else if (uri.contains("song")) {
|
||||
|
||||
String songId = parameters.get("id");
|
||||
this.songUri = RetroUtil.getSongUri(context, Long.parseLong(songId));
|
||||
|
||||
if (songUri != null) {
|
||||
String mediasend = "audio/mp3";
|
||||
FileInputStream fisSong = null;
|
||||
File song = new File(songUri.getPath());
|
||||
try {
|
||||
fisSong = new FileInputStream(song);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Response.Status st = Response.Status.OK;
|
||||
|
||||
//serve the song
|
||||
return newFixedLengthResponse(st, mediasend, fisSong, song.length());
|
||||
}
|
||||
|
||||
}
|
||||
return newFixedLengthResponse("Error");
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue