android - Music player throws an error when getDuration() is called -
i creating single app has media player controllers play, pause etc 2 labels can display current duration , total duration. app force closes when , throws error retrieving total duration via getduration(). can please me out this?
make sure have initialized mediaplayer.if attampt call getduration() on uninitialized mediaplayer object crash application.
check following snippet reference.
mediaplayer player = new mediaplayer(); <<<<<<<<< try { player.setdatasource("/sdcard/0.ogg"); player.prepare(); log.v("duration", player.getduration() + ""); player.start(); } catch (exception e) { e.printstacktrace(); }
Comments
Post a Comment