Trouble with MediaPlayer

21 views
Skip to first unread message

Yaakov Gesher

unread,
Jun 18, 2015, 9:58:22 AM6/18/15
to codenameone...@googlegroups.com
Hi

I'm trying to use MediaPlayer, copying the code from KitchenSink, but it's not working, neither in the simulator or on an Android device, even though the video in KitchenSink plays on my Android device.  This is my code:

                    MediaPlayer mp = new MediaPlayer();
                    try{
                        mp.setPlayIcon(Resources.openLayered("/theme").getImage("play_button.png"));
                        mp.setPauseIcon(Resources.openLayered("/theme").getImage("font-419.png"));
                        mp.setDataSource(URL_PREFIX+"uploads/"+(String)fileInfo.get("path"));
                        
                        
                    }catch(Exception e){
                        e.printStackTrace();
                    }
                    mStateMachine.findVideoContainer(c).addComponent(BorderLayout.CENTER, mp);

I think the real problem is that somehow the network thread is being blocked, or the queue in any case, since URLImages aren't loading, either, but data from a plain network call using ConnectionRequest works fine.  I've attached the project source code.  I really hope someone can help, I'm getting very frustrated with these problems.  The MediaPlayer and URLImages that aren't working in the ConversationRenderer class.

Thanks a ton to anyone who can help
userclasses.zip

Yaakov Gesher

unread,
Jun 18, 2015, 10:06:49 AM6/18/15
to codenameone...@googlegroups.com
Further details: the images and videos are from a server I'm in charge of, no problems with permissions or anything like that.  The MediaPlayer in the simulator shows only the buttons, not the video, and on the Android device it doesn't even show the buttons.  Also, I try changing the buttons using setPlayIcon() and setPauseIcon(), but in the simulator the default texts remain.

Shai Almog

unread,
Jun 18, 2015, 10:40:59 AM6/18/15
to codenameone...@googlegroups.com, orme...@gmail.com
Hi,
seriously don't do this:
Resources.openLayered("/theme")...
You are loading a huge file over and over again...
What's URL_PREFIX?

Yaakov Gesher

unread,
Jun 18, 2015, 11:10:10 AM6/18/15
to codenameone...@googlegroups.com, orme...@gmail.com
Okay, I must have seen that somewhere and just copied it; I certainly didn't think of it on my own.  URL_PREFIX is just the domain name I made into a constant because I use it for all my network calls. 
That's definitely not the problem.  Something I did is preventing the images and video from downloading, but I have no idea what.

Yaakov Gesher

unread,
Jun 18, 2015, 11:32:18 AM6/18/15
to codenameone...@googlegroups.com
I changed the resource loading, and on a tip from another question I asked I looked at the EDT violations.  There are about a dozen when the Form with the MediaPlayer is shown, most or all of them tracing back to MediaPlayer.  Should I put the initialization of MediaPlayer on another thread?  Could this be causing it not to show up at all, on the Android device?

Yaakov Gesher

unread,
Jun 18, 2015, 1:20:47 PM6/18/15
to codenameone...@googlegroups.com
I put the line mediaPlayer.setDataSource() on a separate thread, but I'm getting the same behavior: on the device nothing shows up, on the simulator just the controls.

Chen Fishbein

unread,
Jun 18, 2015, 3:16:22 PM6/18/15
to codenameone...@googlegroups.com, orme...@gmail.com
Hi,
1)Notice the MediaPlayer buttons won't show up on Android because the video player has it's own control buttons, if this method returns true Display.getInstance().isNativeVideoPlayerControlsIncluded() the MediaPlayer hides it's buttons and lets the underlying implementation to show it's control buttons. 

2)Are you trying to show the MediaPlayer on a List Renderer? if yes it will probably won't work since the renderer is stateless, either way the video is a native peer component so using that in a scrollable pane is probably a bad idea.

3)Try to create a simple border layout form with your media player in the center and see if that works.

Yaakov Gesher

unread,
Jun 21, 2015, 4:20:59 AM6/21/15
to codenameone...@googlegroups.com, orme...@gmail.com
Maybe I'll try your last suggestion further on down the line.  For the moment I gave up and put the video in a WebBrowser component instead, in a separate form, and it works fine.
Reply all
Reply to author
Forward
0 new messages