• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Playing Video in My App

Can anyone shed some light on the current issue I am having with playing videos within my app. The code worked before but with the upgrades to android it no longer works which is frustrating.

Here is an example of my code below:

Code:
private String path = "https://www.domainname.tv/AppVideos/SP/Video.mp4";
    private VideoView mVideoView;

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

ImageButton btn = (ImageButton)rootView.findViewById(R.id.playButtonStage1);
        btn.setOnClickListener(this);

 mVideoView = (VideoView) rootView.findViewById(R.id.videoViewStage1);

        if (path.equals("")) {
            // Tell the user to provide a media file URL/path.
            Toast.makeText(getActivity(), "Please edit VideoViewDemo Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show();
//            return;
        } else {
            /*
             * Alternatively,for streaming media you can use
             * mVideoView.setVideoURI(Uri.parse(URLstring));
             */
            mVideoView.setVideoPath(path);
            mVideoView.setMediaController(new MediaController(getActivity()));
            mVideoView.requestFocus();
            //mVideoView.bringToFront();

            mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                [USER=1021285]@override[/USER]
                public void onPrepared(MediaPlayer mediaPlayer) {
                    // optional need Vitamio 4.0
                    mVideoView.getCurrentPosition();
                }
            });

        }

        return rootView;

        // Inflate the layout for this fragment
        //return inflater.inflate(R.layout.fragment_stress_management, container, false);
    }

[USER=1021285]@override[/USER]
    public void onClick(View v) {

        mFragmentManager = getActivity().getSupportFragmentManager();
        mFragmentTransaction = mFragmentManager.beginTransaction();
        //mFragmentTransaction.replace(R.id.containerView, new TabFragment()).commit();

        ImageButton btn = (ImageButton)v.findViewById(R.id.playButtonStage1);
        Intent webLink = new Intent(Intent.ACTION_VIEW);

        switch (v.getId()){
            case R.id.playButtonStage1:
                mVideoView.start();
                btn.setVisibility(View.GONE);
                break;
}

Any help would be appreciated as I have tried everything. All it says is that is can't play video :/
 
Last edited by a moderator:
Dunno, especially since I not read code not in tags...

But recently I had problems and it came down to the limited number of codecs installed. Had to research some very exact encoding via ffmpeg, there's lots of versions of mp4
 
I realised that my mp4 videos are not supported on newer devices, so need to find convert them to a format that does work. Do you know the exact format that android requires to play videos? Also what I can use to convert that exact format?
 
I find it surprising that you're having trouble playing an mp4 file. It's a standard video format. What makes you think it isn't supported by the VideoView?
 
I find it surprising that you're having trouble playing an mp4 file. It's a standard video format. What makes you think it isn't supported by the VideoView?
I know its not supported because I have tested it. I downloaded an example video which was an mp4 and it worked. Mine is an mp4 and isn't working , so it's something to do with the codec.
 
Now that I have realised what this issue is, I am trying to get the video URL from firebase storage. I am coming across some problems though, can anyone shed some light on my coding here.

//First I create my Firebase Storage Instance then I get the reference
private FirebaseStorage storage = FirebaseStorage.getInstance();
private String path;
StorageReference videoStorageRef = storage.getReference();

// I have then called my OnStart Method to set the video path for my view though it doesn't seem to be working. Here is my method below:

public void onStart() {
super.onStart();

videoStorageRef.child("AppWelcomeVideo.mp4").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@override
public void onSuccess(Uri uri) {

path = videoStorageRef.getDownloadUrl().toString();
mVideoView.setVideoPath(path);

}
}).addOnFailureListener(new OnFailureListener() {
@override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getActivity(),"Video URL Not Downloaded", Toast.LENGTH_SHORT).show();
}
});

}

If anyone can point out where I am going wrong that would be much appreciated.

Thanks
Andy
 
Back
Top Bottom