Niana
Niana

Reputation: 1047

VideoView not playing in Android Application

Scenario

I have an Android App that utilizes a master/details layout. So When I click "Videos" in the left panel, it navigates to a new panel where the video name and link is downloaded. Upon then selecting a title, the left panel hides and the video begins to play.

Problem

I've use a videoview, and oddly, I cant get the video to play. I dont really get an error, However the screen remains black, and I believe i hear the sound from the first few second of the video followed by the image i uploaded and no image.

See Code

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    view = inflater.inflate(R.layout.fragment_drone_life3, null);
    vidView=(VideoView)view.findViewById(R.id.ivEvent);
    context=this.getActivity();
    return view;
}
 public void onItemClick(AdapterView<?> adapterView, View view,
                                    int position, long id) {
                if (new ConnectionDetector(context).isConnectingToInternet()) {
//get VidLink variable of item in this location and place in the var videoLink
                    videoLink = eventsDTOs.get(position).getVidLink();

                    try {

                        MediaController mediaController = new MediaController(getContext());
                        mediaController.setAnchorView(vidView);
                        Uri video = Uri.parse(videoLink);
                        vidView.setMediaController(mediaController);
                        vidView.setVideoURI(video);
                        vidView.start();
                        MainActivity.closeSlidingDrawer();
                    } catch (Exception e) {
                        // TODO: handle exception
                         Toast.makeText(getContext(), "Error connecting", Toast.LENGTH_SHORT).show();
                    }


                   // new TaskGetEventImage().execute(eventsDTOs.get(position).getId());
                } else {
                    Toast.makeText(context, context.getResources().getString(R.string.NETWORK_ERROR),Toast.LENGTH_LONG).show();
                }
            }

enter image description here

Upvotes: 0

Views: 1605

Answers (2)

Niana
Niana

Reputation: 1047

Solved this, apprantly the error was my server doing some encoding that the phone couldnt handle.

Upvotes: 0

Nitin Karande
Nitin Karande

Reputation: 1325

For playing video from URL

   VideoView videoView=(VideoView) findViewById(R.id.myVideo);
   videoView.setVideoURI(Uri.parse("http://website.com/somevideoname.mp4"));
   videoView.setMediaController(new MediaController(this));
   videoView.requestFocus();
   videoView.start();

For playing video from SD card or internal storage

    MediaController vidControl;
    String sdPath;

    VideoView videoView=(VideoView) findViewById(R.id.myVideo);
    vidControl = new MediaController(this);
    vidControl.setAnchorView(videoView);
    videoView.setMediaController(vidControl);
    videoView.setVideoPath(sdPath);
    videoView.requestFocus();
    videoView.start();

I will suggest to try to use above solution for playing video.

Upvotes: 1

Related Questions