Am playing video using this following code. Video is playing am hearing audio. But video view showing black screen.
void playVideo(){
videoPlayer.setVisibility(View.VISIBLE);
videoPlayer.setVideoURI(Uri.parse(path));
videoPlayer.setMediaController(new MediaController(this));
videoPlayer.requestFocus();
videoPlayer.start();
}
please tell the solution.
Related
I have a VideoView, and I want to play a short looped video with no audio. The problem is, when I'm listening to a book or music through my phone and then I get to the activity that plays this looped video, my music is paused. Is there a way to play the video without interrupting whatever audio might be already playing on the phone?
videoView.setVideoURI(descriptionVideo.getUri(getPackageName()));
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.setVolume(0f,0f);
mediaPlayer.setLooping(true);
videoView.start();
}
});
I think it's because the VideoView asked for audio focus.
You could try below
videoView.setAudioFocusRequest(AudioManager.AUDIOFOCUS_NONE)
I am trying to load the following free online camera in my app (site: http://www.earthcam.com)
for example, this video.
and I found the video address by IDM (http://video3.earthcam.com/fecnetwork/5187.flv/chunklist_w664887517.m3u8)
I loaded the video in my app with the following code:
String VideoURL = "http://video3.earthcam.com/fecnetwork/5187.flv/chunklist_w664887517.m3u8";
MediaController mediacontroller = new MediaController(MainActivity.this);
mediacontroller.setAnchorView(videoview);
// Get the URL from String VideoURL
Uri video = Uri.parse(VideoURL);
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);
videoview.requestFocus();
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
videoview.start();
}
});
Now I have two problems
How can I play the video in my app with the original url(for example www.earthcam.com/usa/illinois/chicago/field/?cam=fieldmuseum)
How can I display all tools (zoom in, zoom out, volume, stop, pause, like, view, map, etc.)
First question why the video is not playing: the support of a livestream in MediaController is limited. I would suggest you to ExoPlayer https://github.com/google/ExoPlayer
It should handle a livestream playback.
Second question: in order to display all tools that you mentioned you would need an access to the control of the camera either via API or via URL parameters. Then you would need to add this buttons as an overlay on top of the video player and connect buttons to the API calls. However, I don't think that EarthCam provides public API for a camera control.
Im trying to understand how to add video to my application using the VideoView container but so far I've never been able to view a video and all i receive is an error 'Can't play this video'.
I have a simple method that load's the video:-
private void setupVideo() {
VideoView videoView = (VideoView)findViewById(R.id.videoView);
videoView.setVideoPath("video/Test_Movie.m4v");
videoView.start();
}
I have tried converting the video to many H264, H263 , 3gp formats but I can find anything that works.I even have downloaded a video that said worked in a book i have but still doesn't work.
any help appreciated!
thx.
I'm trying to create a activity with a Video Player.
The problem is that in some devices (ex. Android 4.0.4) when I try to play local video the VideoView shows LogCat error :
MediaPlayer(6757): Error (1,-2147483648)
And on screen:
"Cannot play video. Sorry, this video cannot be played"
The videos be recorded with MediaRecorder and this is the config of MediaRecorder
public boolean initRecorder(){
myRecorder = new MediaRecorder();
myRecorder.setCamera(myCamera);
myRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
myRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
myRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
myRecorder.setOutputFile(getVideoFilePath()); //videopath.mp4
myRecorder.setVideoSize(size.width, size.height);
myRecorder.setPreviewDisplay(mySurfaceHolder.getSurface());
if(prepareRecorder()) return true;
else return false;
}
And played with VideoView like this:
VideoView vidDisplay = (VideoView) viewLayout.findViewById(R.id.vidDisplay);
Uri uri = Uri.parse(_imagePaths.get(position));
vidDisplay.setVideoURI(uri);
vidDisplay.setMediaController(new MediaController(_activity));
vidDisplay.requestFocus();
vidDisplay.start();
EDIT:
The problem is related to the user permissions of the video. Is there a way to create aguna videos with MediaRecorder with read permissions for everyone?
I tried to open the file and then make setReadable(true) but this not work
Can someone help me?
Thanks
I'm using VideoPlayer in my app. It play everything fine but when I want to scroll on the media player's bar, usually it gives me the error : Sorry, this video cannot be played. and I have to restart the video to watch it again. All I found is if I stop the video and scroll the bar it will be fine. I just wonder how can I fix this problem ? how can I access to media player's bar. Hens I can pause the video onClick. My code:
MediaController mediaController = new MediaController(
rootView.getContext());
mediaController.setAnchorView(video);
Uri uri = Uri.parse(passVideo.file_link);
video.setMediaController(mediaController);
video.setVideoURI(uri);
video.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
mProgress.setVisibility(View.INVISIBLE);
video.requestFocus();
video.start();
}
});
Many people get this error like you,
Bugs :
Sorry this video is not valid for streaming to this device.
Sorry, this video can not be played.
You can find out at Sorry, this video is not valid for streaming to this device in Http streaming android
Thanks,