1. Download our Official Android App: Forums for Android!

Playing Video in My App

Discussion in 'Android Development' started by Andrew Brine, Nov 24, 2017.

  1. Andrew Brine

    Andrew Brine Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Nov 24, 2017

    Nov 24, 2017
    5
    0
    5
    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 (Text):
    1.  
    2. private String path = "https://www.domainname.tv/AppVideos/SP/Video.mp4";
    3.     private VideoView mVideoView;
    4.  
    5. public View onCreateView(LayoutInflater inflater, ViewGroup container,
    6.                              Bundle savedInstanceState) {
    7.  
    8. ImageButton btn = (ImageButton)rootView.findViewById(R.id.playButtonStage1);
    9.         btn.setOnClickListener(this);
    10.  
    11.  mVideoView = (VideoView) rootView.findViewById(R.id.videoViewStage1);
    12.  
    13.         if (path.equals("")) {
    14.             // Tell the user to provide a media file URL/path.
    15.             Toast.makeText(getActivity(), "Please edit VideoViewDemo Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show();
    16. //            return;
    17.         } else {
    18.             /*
    19.              * Alternatively,for streaming media you can use
    20.              * mVideoView.setVideoURI(Uri.parse(URLstring));
    21.              */
    22.             mVideoView.setVideoPath(path);
    23.             mVideoView.setMediaController(new MediaController(getActivity()));
    24.             mVideoView.requestFocus();
    25.             //mVideoView.bringToFront();
    26.  
    27.             mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    28.                 [USER=1021285]@override[/USER]
    29.                 public void onPrepared(MediaPlayer mediaPlayer) {
    30.                     // optional need Vitamio 4.0
    31.                     mVideoView.getCurrentPosition();
    32.                 }
    33.             });
    34.  
    35.         }
    36.  
    37.         return rootView;
    38.  
    39.         // Inflate the layout for this fragment
    40.         //return inflater.inflate(R.layout.fragment_stress_management, container, false);
    41.     }
    42.  
    43. [USER=1021285]@override[/USER]
    44.     public void onClick(View v) {
    45.  
    46.         mFragmentManager = getActivity().getSupportFragmentManager();
    47.         mFragmentTransaction = mFragmentManager.beginTransaction();
    48.         //mFragmentTransaction.replace(R.id.containerView, new TabFragment()).commit();
    49.  
    50.         ImageButton btn = (ImageButton)v.findViewById(R.id.playButtonStage1);
    51.         Intent webLink = new Intent(Intent.ACTION_VIEW);
    52.  
    53.         switch (v.getId()){
    54.             case R.id.playButtonStage1:
    55.                 mVideoView.start();
    56.                 btn.setVisibility(View.GONE);
    57.                 break;
    58. }
    59.  
    Any help would be appreciated as I have tried everything. All it says is that is can't play video :/
     

    Advertisement

    #1 Andrew Brine, Nov 24, 2017
    Last edited by a moderator: Nov 24, 2017
  2. Bonked

    Bonked Newbie
    Rank:
     #1,339
    Points:
    16
    Posts:
    17
    Joined:
    Aug 11, 2017

    Aug 11, 2017
    17
    3
    16
    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
     
  3. Andrew Brine

    Andrew Brine Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Nov 24, 2017

    Nov 24, 2017
    5
    0
    5
    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?
     
  4. LV426

    LV426 Illegitimi non carborundum
    Moderator
    Rank:
     #23
    Points:
    1,238
    Posts:
    5,375
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    5,375
    7,042
    1,238
    Male
    Software developer
    South West of England
    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?
     
  5. Bonked

    Bonked Newbie
    Rank:
     #1,339
    Points:
    16
    Posts:
    17
    Joined:
    Aug 11, 2017

    Aug 11, 2017
    17
    3
    16
  6. Andrew Brine

    Andrew Brine Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Nov 24, 2017

    Nov 24, 2017
    5
    0
    5
    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.
     
  7. Andrew Brine

    Andrew Brine Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Nov 24, 2017

    Nov 24, 2017
    5
    0
    5
  8. Andrew Brine

    Andrew Brine Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Nov 24, 2017

    Nov 24, 2017
    5
    0
    5
    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
     

Share This Page

Loading...