forked from naman14/Timber
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
158 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.naman14.timber.cast; | ||
|
||
import android.content.Context; | ||
import android.net.Uri; | ||
|
||
import com.naman14.timber.utils.TimberUtils; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.util.Map; | ||
|
||
import fi.iki.elonen.NanoHTTPD; | ||
|
||
public class WebServer extends NanoHTTPD { | ||
|
||
private Context context; | ||
private Uri songUri, albumArtUri; | ||
|
||
public WebServer(Context context) { | ||
super(8080); | ||
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 | ||
|
||
Uri url = Uri.parse(uri); | ||
String albumId = url.getQueryParameter("id"); | ||
this.albumArtUri = TimberUtils.getAlbumArtUri(Long.parseLong(albumId)); | ||
|
||
if (albumArtUri != null) { | ||
String mediasend = "image/jpg"; | ||
FileInputStream fisAlbumArt = null; | ||
File albumArt = new File(albumArtUri.getPath()); | ||
try { | ||
fisAlbumArt = new FileInputStream(albumArt); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
Response.Status st = Response.Status.OK; | ||
|
||
//serve the song | ||
return newFixedLengthResponse(st, mediasend, fisAlbumArt, albumArt.length()); | ||
} | ||
|
||
} else if (uri.contains("song")) { | ||
|
||
Uri url = Uri.parse(uri); | ||
String songId = url.getQueryParameter("id"); | ||
this.songUri = TimberUtils.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"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
|
||
<item | ||
android:id="@+id/media_route_menu_item" | ||
android:title="@string/cast" | ||
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider" | ||
app:showAsAction="always" /> | ||
|
||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters