android - Converting string to data -


i getting duration of audio file , convert int , convert int string , string 00:32 . converted string correct, problem convert string data

here code:

            file file = new file(environment.getexternalstoragedirectory()+"/myimages/.audio1.wav");             mediaplayer mp = new mediaplayer();             fileinputstream fs = null;             filedescriptor fd = null;             try {                 fs = new fileinputstream(file);             } catch (filenotfoundexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }             try {                 fd = fs.getfd();             } catch (ioexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }             try {                 mp.setdatasource(fd);             } catch (illegalargumentexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (illegalstateexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (ioexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }             try {                 mp.prepare();             } catch (illegalstateexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (ioexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }              int length = mp.getduration()/1000;             mp.release();              string audiotime = string.valueof(length);              simpledateformat sdf = new simpledateformat("mmss");             try {               date d = sdf.parse(audiotime);               textview1.settext(audiotime);             } catch (parseexception ex) {              } 

two things, important, use original string text textview. should textview1.settext(d.tostring());

secondly, should use "mm:ss" format, instead of "mmss".

note use format function of simpledateformat. return stringbuffer, might more appropriate since need string representation

source: android documentation


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -