IOS device: media.getTime() and media.getDuration() are returning mismatch values

41 views
Skip to first unread message

ohadm...@gmail.com

unread,
Aug 24, 2015, 6:46:42 PM8/24/15
to CodenameOne Discussions
IOS device: media.getTime() and media.getDuration() are returning mismatch values

ios.newVM=false was solved this issue but cannot be used anymore.

new Thread(new Runnable() {
                    @Override
                    public void run() {
                        String audioURL = "http://......";
                        final Media media = Display.getInstance().createMedia(audioURL, false, null);
                        if (media != null) {
                            media.prepare();
                            media.play();
                        }
                        while(true) {
                            try {
                                if(media!=null && media.isPlaying()) {
                                   final SimpleDateFormat formatter = new SimpleDateFormat("mm:ss");
                                   System.out.println(formatter.format(media.getTime()) + "/" +formatter.format(media.getDuration()));                                                                            
                                }
                            }catch(Exception e) {
                                
                            }
                            try {Thread.sleep(500);}catch (Exception e) {};
                        }
                    }
                }).start();

Shai Almog

unread,
Aug 25, 2015, 12:45:00 AM8/25/15
to CodenameOne Discussions, ohadm...@gmail.com
Can you clarify if this is an issue of the formatter or an issue of the actual time?
I'm betting the differences relate to how the formatter/date work.
E.g. printout media.getTime and media.getDuration where you should see almost identical numbers.

ohadm...@gmail.com

unread,
Aug 25, 2015, 4:37:00 AM8/25/15
to CodenameOne Discussions, ohadm...@gmail.com
It looks like the problem is in the formatter.

Shai Almog

unread,
Aug 29, 2015, 10:20:37 AM8/29/15
to CodenameOne Discussions, ohadm...@gmail.com
Sorry for the delay. This got under a bunch of other comments and I missed it.

You need to use the SimpleDateFormat from the com.codename1.l10n package to get consistent behavior across devices.
How are you constructing this formatter and with what values.
If you have a test case that can run with the com.codename1.l10n version it should be pretty easy to isolate the cause since its all Java code and no native code.

ohadm...@gmail.com

unread,
Aug 30, 2015, 4:31:32 PM8/30/15
to CodenameOne Discussions, ohadm...@gmail.com
Thanks Shai, I used java.text.SimpleDateFormat instead of com.codename1.l10n.SimpleDateFormat.
I will take a look now.
Reply all
Reply to author
Forward
0 new messages