Reputation: 866
Does the native code of the VideoView give access to the received packets of the video before or after decoding it? I need to access these packets in order to transmit them to another device. The initial solution is to modify the Android native code. Other possible solutions that I found are to use GStreamer or FFmpeg libraries. I need bit guidance in order to achieve that goal.
Assume the phone is rooted.
Upvotes: 2
Views: 596
Reputation: 3034
Short answer is no, not that I know of.
Long answer is that you haven't given enough detail. What data exactly do you need access to? Are you writing an application, or modifying your OS to do this to other applications?
The code that actually fetches a remote video is in MediaPlayer
and is native. See the following method in MediaPlayer
:
private void setDataSource(/* snip */) throws /* snip */ {
/* snip */
else if (scheme != null) {
// handle non-file sources
nativeSetDataSource(
MediaHTTPService.createHttpServiceBinderIfNecessary(path),
path,
keys,
values);
return;
}
/* snip */
Unfortunately for you, almost all of the relevant MediaPlayer
code is native
, and if not, it is private (so subclassing will not work here).
However, depending on what you need to do, you could possibly override VideoView
method setVideoURI(Uri, Map<String, String>)
, which is public. Here you can grab the URI and then proxy it through your own web service, or something. This isn't quite what you were asking, though.
Or, you could possibly look into modifying the Surface
that is drawn to by MediaPlayer
. Most of the relevant code is still native
though.
The final possibility that I'll mention (there are probably hundreds of possible approaches) would be to modify the MediaHTTPService
class. This appears to be used by MediaPlayer
, but I can't be sure because if it's used, it's used in native code.
This answer recommends finding the native code at androidxref.com
Edit:
As requested, here is a little more detail about what the "proxy server" solution might look like. I don't know the implementation details on Android.
Basically, when you get a URL to play in the VideoView
, you pass it to your own server instead. Something like startProxyServer(videoUrl)
. This starts a server, which downloads and then re-hosts the video. To get this working locally, start a webserver listening on localhost
. The server just downloads the video at videoUrl
, saves it locally, and then hosts it at localhost:port/?video=${videoUrl}
.
So in very high-level pseudo-code the server could look like.
public void startProxyServer(String videoUrl) {
int PORT = 28641; // random port
File f = downloadFile(videoUrl);
saveFile(f, '/path/to/server/storage');
startWebServer('localhost', PORT);
}
So now you give localhost:port/?video=${videoUrl}
as url to the videoView
instead. Also, now other videoView
instances can download from that same localhost url.
To make it work with other phones, your server of course couldn't run on localhost
.
Of course I've not implemented this, but it's just one solution I can think of.
Upvotes: 2