android - AVI/MP4 on videoview -


i trying run avi/mp4 video on videoview in app, when app open appears "can't play video", testing on mobile.

videoview = (videoview)findviewbyid(r.id.videoview); mediacontroller mediacontroller = new mediacontroller(this); mediacontroller.setanchorview(videoview); videoview.setmediacontroller(mediacontroller); videoview.setvideopath("/sdcard/"+file); videoview.start(); 

the log:

03-28 20:52:30.723    8474-8474/mjksites.loopvideo d/mediaplayer﹕ getmetadata 03-28 20:52:30.842    8474-8491/mjksites.loopvideo w/mediaplayer﹕ info/warning (3, 0) 03-28 20:52:32.530    8474-8490/mjksites.loopvideo e/mediaplayer﹕ error (1, -1004) 03-28 20:52:32.538    8474-8474/mjksites.loopvideo e/mediaplayer﹕ error (1,-1004) 03-28 20:52:32.538    8474-8474/mjksites.loopvideo d/videoview﹕ error: 1,-1004 

android not support avi video container format - message seeing normal message when try play unsupported video format.

see here date list of supported formats:

note trying play 'avi/mp4' video - unusual avi , mp4 alternative video containers, video 1 format or there other.

updated answer

ok - have checked video posted below in comments , play on android 4.4.2 device.

the following code works (it played video) , may useful try in app (updated use own view id, video path etc). use in fragment, can change activity if use case:

public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {      rootview = inflater.inflate(r.layout.fragment_item_detail, container, false);      //create video player , set video path     videoplayerview = (videoview) rootview.findviewbyid(r.id.video_area);     if (videoplayerview == null) {         log.d("itemdetailfragment","oncreateview: videoplayerview null");         return null;     }      //set video path , make sure first frame shown instead of black screen     videoplayerview.setvideopath(selectedvideoitem.videopath);      videoplayerview.seekto(100);      //set mediacontroller (the video control bar) match size of videoview - trick      //from stackoverflow answer makes sure sized correctly, calling setanchroview after     //video loaded , hence knows right sze.     final context mcontext = this.getactivity();     videoplayerview.setonpreparedlistener(new onpreparedlistener() {         @override         public void onprepared(mediaplayer mp) {             //add listener size change correctly set controls             mp.setonvideosizechangedlistener(new onvideosizechangedlistener() {                  @override                 public void onvideosizechanged(mediaplayer mp, int width, int height) {                     //add media controller , set position on screen.                     mediacontroller = new mediacontroller(mcontext);                     videoplayerview.setmediacontroller(mediacontroller);                     mediacontroller.setanchorview(videoplayerview);                 }             });         }     });      return rootview; } 

also, make sure app has permission read external storage media player errors caused underlying problems , not helpfully reported. following line should in manifest:

<uses-permission android:name="android.permission.read_external_storage" /> 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -