I have video player, video is from url. It works- I can start and stop playing video. I would like to have a possibility to move progres in MediaController. I have set the MediaController, but it doesn't work. When I use a video from file i can seek/move the video progress, but with the video from url it doesn't work.
There is my code:
videoFrame = (FrameLayout) findViewById(R.id.videoField);
mediaController = new MediaController(VideoPage.this);
videoPlayer = new VideoView(context);
videoFrame.addView(videoPlayer);
videoPlayer.setVideoURI(Uri.parse(url));
mediaController.setMediaPlayer(videoPlayer);
videoPlayer.setMediaController(mediaController);
videoPlayer.requestFocus();
videoPlayer.start();
You have to check if you can seek forward:
if(videoPlayer.canSeekForward()){
...
}
and this is just possible, when you get a duration for the videostream, but some streams don't have a duration, for example if you stream tv content or a live stream.
int duration = videoPlayer.getDuration()
Related
I'm trying use videocaptur to open video ,but without success.
I tried different video avi codec.
public void OnBtnStart(View view) {
String videopath = "android.resource://com.example.msi.mhltryagain/"+R.raw.testmjpeg;
VideoView videoview = (android.widget.VideoView) findViewById(R.id.VideoView);
Uri uri = Uri.parse("android.resource://com.example.msi.mhltryagain/"+R.raw.test);
videoview.setVideoURI(uri);
videoview.start();
VideoCapture cap = new VideoCapture(videopath);
boolean capGrab = cap.grab();
if (cap.isOpened()){
Toast.makeText(this,"is opened",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this,"isn't opened"+capGrab,Toast.LENGTH_SHORT).show();
}
}
The video path is certainly good because it correctly plays the test video. When i press the button is displayed "isnt'opened false". Why video can't by opened?
I am creating by myself a controller for a VideoView (I know it's easier to use a Controller, but it's a school homework), so the app appearance is the following (a VideoView with a SeekBar and 3 Buttons)
In the onCreate method I've written this code
VideoView vwVideo = (VideoView) findViewById(R.id.videoView);
vwVideo.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.baby);
SeekBar skbPosition = (SeekBar) findViewById(R.id.seekBarVideo);
skbPosition.setMax(vwVideo.getDuration());
but getDuration() returns -1, maybe because the video hasn't been loaded yet (*.mp4, 4.47 MB, 00:01:44), so I decided to set the maximum value of the SeekBar when the button "Play" is clicked but I don't know if this is the best way to solve the problem.
Is there a better solution?
If you want to get the duration of the video you can do this by using MediaMetadataRetriever.
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
//use setDataSource() functions to set your data source
retriever.setDataSource(context, Uri.fromFile(videoFile));
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long timeInMillisec = Long.parseLong(time);
Update me if any problem.
now I'm developing an android Video on Demand or Audio on Demand Player, I notice there's a function in package android.net.Uri, part of my code of play the video or audio is like this:
Play Audio part:
mPlayer = new MediaPlayer();
mPlayer = MediaPlayer.create(this, Uri.parse("http://.../MJ.mp3"));
mPlayer.setLooping(true);
mPlayer.start();
Play Video Part:
VideoView vidView = (VideoView)findViewById(R.id.myVideo);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
String vidAddress = "https://.../ABC.mp4";
Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
vidView.start();
I'm wondering does this satisfy the video or audio on demand request? In an other word, when I play the audio or video using the URI function, does it work like Youtube, which downloads just part of the video and plays the video, or download the whole file first then play it?
I am developing a video based android application. I want to play a video (Video Format: mp4) from a URL. But it's not live stream video stored in the server. Get video URL from JSON object and playing video. The video is playing but not in a good manner.
Sometimes the audio is mismatched then take more time to play some take more time to buffer. But with the same video and same wifi speed I have on my system when playing with chrome it's playing well. I don't know what I am doing wrong? I also tried with android video view but the same problems occurred.
My code to start video player
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(uri), "video/*");
startActivity(intent);
My code to playing with video view
VideoView vidView = (VideoView)findViewById(R.id.myVideo);
String vidAddress = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";
Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
vidView.start();
What android version did you try? Because https is not supported before android 3.1.
Check supported protocols and media formats here
You can use the MediaPlayer to do this.
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
Map<String, String> headers = new HashMap<String, String>();
headers.put("rtsp_transport", "tcp");
headers.put("max_analyze_duration", "500");
mMediaPlayer.setDataSource(context, Uri.parse(videoUrl), headers);
Can we play flv stream videos in Android without using WebView, it's too slow? I mean play .flv video directly from url. Any ideas? VideoView now work with the .flv link.
I got it to work using this code. You can play it local from your device or stream it from online. You have to drag an instance of the FLV COMPONENT in your movie and then just delete it from the stage to it remains in your library.
var myVideo:FLVPlayback = new FLVPlayback();
myVideo.source = "content/video/BeauIntro.flv"; // CHANGE THIS TO YOUR FLV
myVideo.autoPlay = true;
// I am choosing to load the flv into an empty movie but you don't have to.
var my_mc:MovieClip = new MovieClip();
addChild(my_mc);
/// These are important because it can mess up position with out it.
myVideo.align = StageAlign.TOP_LEFT;
myVideo.scaleMode = VideoScaleMode.EXACT_FIT;
// Setting the video to the screen size of device
myVideo.width = stage.stageWidth;
myVideo.height = stage.stageHeight;
// Adding my FLV into my empty movie.
my_mc.addChild(myVideo);
//Setting the empty Movie Clip for the video to the screen size of device
my_mc.width = stage.stageHeight;
my_mc.height = stage.stageHeight;
/// This will run when the video stops
myVideo.addEventListener(fl.video.VideoEvent.COMPLETE, VideoStopped);
function VideoStopped(e:Event):void
{
myVideo.stop();
myVideo.visible = false; /// I wanted it to not be seen after playing.
trace("stopped");
myVideo.removeEventListener(fl.video.VideoEvent.COMPLETE, VideoStopped);
}
try this:
String url=your url here;
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "flv-application/octet-stream");
startActivity(intent);