I need play video from samba to android device streaming. I've been look for this question and someone say that :
Using JCIFS to scan for and "see" the share: http://jcifs.samba.org/
Implementing a simple HTTP server (NanoHttpd) to stream the content
via http: https://github.com/NanoHttpd/nanohttpd
Passing the http://localhost/myvideo link to the VideoView
I'm already use JCIFS to get SmbFile in my project and I also get inputstream( smbfile.getInputStream() ).
Now I import NanoHttpd and I create simple HTTP server that http address ishttp://localhost:8080
private class MyHTTPD extends NanoHTTPD {
public MyHTTPD() throws IOException {
super(8080);
}
#Override
public Response serve(String uri, String method, Properties header, Properties parms, Properties files) {
InputStream is = new SmbFile(filePath,auth).getInputStream();
//return index as response
return new NanoHTTPD.Response(HTTP_OK, "video/mp4", is);
}
}
server = new MyHTTPD();
server.start();
But my http address is different from http://localhost/myvideo, I don't know how to get right http address and put it in to VideoView.
I don't know how to get path like http://localhost/myvideo .
Thanks for help....
The other question : Can I use VideoView playing video from InputStream ?
Related
We can play mp3 files from browsers, Social Networks, Apps... I want to get URL of mp3 when it's playing. One way here is to create an extension in the browser. But in other apps we can't. Here is an example:
I go to some site and open some mp3:
If you can see the music is playing and it has a URL. I want to get this URL when music starts playing. How can I do that? And how can I get URL of music which is playing in some app? Is it possible?
If you can see the music is playing and it has a URL. I want to get
this URL when music starts playing. How can I do that?
If you are loading the website into a WebView, the easiest possible way you can get the URL by intercept the requests through WebViewClient and check if the URL contains '.mp3'. See the following example,
public class YourWebViewClient extends WebViewClient {
#Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
String url = request.getUrl().toString();
if (url.contains(".mp3")) {
Log.d(TAG, "MP3 url = [" + url + "]");
}
return super.shouldInterceptRequest(view, request);
}
}
And how can I get URL of music which is playing in some app? Is it
possible?
Yes possible but not too easy especially if you are going to get it from SSL traffic. To sniff other app's network traffic you need to perform MITM. There are a couple of apps in the play store which are doing exactly the same thing. You can look into HttpCanary app for reference. Basically you need to perform the following steps -
Set up a proxy server
Configure your device to pass its network traffic to that proxy server
Ask the proxy server to give you the network data
Analyze the network data to see if it contains 'mp3' URL
If you need to intercept https traffic, you need to generate and install an SSL certificate.
First import the JSOUP library from maven
compile 'org.jsoup:jsoup:1.12.1'
after that use this code
Document doc = Jsoup.connect(url).get();
System.out.println(doc.title());
Elements h1s = doc.select(".jp-type-single");
System.out.println("Number of results: " + h1s.size());
for (Element element : h1s) {
String mp3Url = element.attr("data-xc-filepath");
System.out.println("mp3 url: " + mp3Url);
file_num++;
URLConnection conn = new URL(mp3Url).openConnection();
InputStream is = conn.getInputStream();
OutputStream outstream = new FileOutputStream(new
File("/users/pelican/downloads/"+file_num+"file.mp3"));
byte[] buffer = new byte[4096];
int len;
while ((len = is.read(buffer)) > 0) {
outstream.write(buffer, 0, len);
}
now let me explain this
JSOUP fetched the webpage using your HTML URL
after that, it converts into doc
and after that, it selects the element by using a select method and here we are getting the first audio tag that we want to search.
Last 3 days I started to learn Spring. I want to send a image from the phone gallery to the spring server. I want to mention that the server is local so I'm using localhost. I saw a tutorial that if I want to send stuff to a local server, the server address is my laptop address + the port (ex. 8080) and I have to connect the phone to the same Wi-Fi as the laptop.
I know how to get the image from the gallery but I don't know how to send it. Many solutions from stackoverflow are old and some classes got deprecated and I can't try their method.
Also, what should I do in the spring controller to receive the image?
You'll have use MultipartFile to upload an image using spring. Please go through following example.
#RequestMapping(value = "/upload", method = RequestMethod.POST)
public String fileUpload(#RequestParam("file") MultipartFile file) {
try {
// Get the file and save it somewhere
byte[] bytes = file.getBytes();
//save file in server - you may need an another scenario
Path path = Paths.get("/" + file.getOriginalFilename());
Files.write(path, bytes);
} catch (IOException e) {
e.printStackTrace();
}
//redirect to an another url end point
return "redirect:/upload-status";
}
Please make sure you can reach to your computer through your mobile device. I believe you may know that Android requires additional privilege to use network connections. So make sure you have permitted your app to access network.
EDIT:
You can use HttpClient to upload file from your mobile app. Please try following code.
HttpClient httpClient = AndroidHttpClient.newInstance("App");
HttpPost httpPost = new HttpPost("http://your-server-url");
httpPost.setEntity(new FileEntity(new File("your-file-path"), "application/octet-stream"));
HttpResponse response = httpClient.execute(httpPost);
I'm working on android app and back-end server Rest API part.
I'm at the point where i need to return some video files from the server back to my android device. How can i do that?
I looked up jersey documantation https://jersey.java.net/documentation/1.19/jax-rs.html#d4e142
and http://www.vogella.com/tutorials/REST/article.html#restjersey_annotations
but din't have any luck figuring this out..
For images i've been using the
#Produces(image/jpg)
Is there a similar way i can do to share mpeg4 or any other video files?
What would be the best approach there?
As android client can stream the video content, try something like this
#GET
#Path("video")
#Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response video() {
File file = new File("C:/Data/video.mp4");
return Response.ok(file, MediaType.APPLICATION_OCTET_STREAM)
.build();
}
I'm writing code to read a file from an FTP URL in order to parse it and store the data in Google App Engine's Datastore. I'm able to get the code working fine when reading test files hosted on my own web server, however when I try to read the data file I need I'm getting a FileNotFoundException.
I'm able to use the same FTP URL in a browser to download the file, and can anonymously connect to the FTP URL in FileZilla, so access shouldn't be a problem, and the file is definitely there. It's a pretty big file, but I've tried to grab smaller files from the same FTP server with no luck either.
Here's the code I have at the moment:
public void doGet(HttpServletRequest req,
HttpServletResponse resp) throws IOException, ServletException {
// works with a URL to my own server & a test.zip, but not this one
final URL url = new URL(
"ftp://gisftp.metc.state.mn.us/google_transit.zip");
// without the privileged action, I get an AccessControlException
ZipInputStream zin = AccessController.doPrivileged(
new PrivilegedAction<ZipInputStream>() {
public ZipInputStream run() {
return getZipStream(url);
}
}
);
ZipEntry zipentry = zin.getNextEntry();
// processing files here
zin.close();
}
// but using the privileged method, we get a FileNotFoundException
public ZipInputStream getZipStream(URL url) {
ZipInputStream zipin = null;
try {
zipin = new ZipInputStream(url.openStream());
} catch (IOException e) {
e.printStackTrace();
}
return zipin;
}
At first I was getting an AccessControlException, but using a PrivilegedAction to open the stream seems to fix that.
I don't have access to the server where the file is stored, so can't change anything there.
I think there is a restriction on the ports that can be connected to from App Engine and FTP (21) is not in the list, this maybe causing the issue. From the URL Fetch documentation;
An app can fetch a URL using HTTP (normal) or HTTPS (secure). The URL specifies the scheme to use: http://... or https://...
The URL to be fetched can use any port number in the following ranges: 80-90, 440-450, 1024-65535. If the port is not mentioned in the URL, the port is implied by the scheme: http://... is port 80, https://... is port 443.
I have been attempting to upload videos to YouTube via the JavaAPI using Direct Uploading. I have been having a problem when I call the insert() method, I get a IOException with the error message
"Error writing request body to the server"
I have verified that the File object I am creating is correct as well as all the details in my VideoEntry object. I have been using Fiddler to monitor the activity from my machine and no request is made to the upload API so the problem is not there. Here is a summary of the code I am using:
VideoEntry newVideo = new VideoEntry();
//Defined video properties such as title and description here.
MediaFileSource ms = new MediaFileSource(videoFile, "video/flv");
newVideo.setMediaSource(ms);
VideoEntry createdEntry = settings.insert(new URL(apiUrl), newVideo);
The IOException is thrown on the insert call (settings is my YouTubeService instance) and the API URL appears to be correct.
Prior to this I have succeeded in uploading this video using the C# API so I know the video file is valid.
--Update
This is the apiURL value:
http://uploads.gdata.youtube.com/feeds/api/users/default/uploads
Make certain that videoFile actually points to the correct local file. The File(String) constructor won't verify that it actually exists. The MediaFileSource constructor and VideoEntry.setMediaSource() method also never check that the file is valid. The error message "Error writing request body to the server" sounds like the insert method can not find the body of the message it is trying to send.
File videoFile = new File("...");
if (videoFile.exists() == false) {
System.err.println("FAIL");
}
to test if the file exists.
If you are under a firewall env and had configured your proxy settings in jvm system properties. The try configuring your youtube service as:
service.setChunkedMediaUpload(MediaService.NO_CHUNKED_MEDIA_REQUEST);
or in your case
settings.setChunkedMediaUpload(MediaService.NO_CHUNKED_MEDIA_REQUEST);
since as you say is your YouTubeService instance.
hope this helps.