Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile
Accepted Solution

Use MediaPlayer to repeat a song?

I have an app where I want background music so I have toggle button to turn on/off the mp3 that plays music.  However when the song ends it doesn't repeat.  So I figure I need to do something with setRepeatMode or repeatMode but I can't get anything to work.  Anybody have sample code with a song repeating?

 

Thanks

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Use MediaPlayer to repeat a song?

if you are using the MediaPlayer control, you can simply listen to the "onPlaybackCompleted" signal and restart the music:

 

MediaPlayer{
  id: myPlayer
  property bool repeatMode: true
  ...
  onPlaybackCompleted: {
    if(repeatMode)
      myPlayer.play();
  }
  ...
}

 

Developer
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile

Re: Use MediaPlayer to repeat a song?

That is not working, cause that QML page to not load.

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Developer
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile

Re: Use MediaPlayer to repeat a song?

[ Edited ]

nevermind I figured it out, it is setRepeatMode()...

 

MediaPlayer{
  id: myPlayer
...
  }

...

Button{
onClicked:{
myPlayer.setRepeatMode(1); myPlayer.play(); } }

 

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Highlighted
Developer
Posts: 135
Registered: ‎11-14-2010
My Device: BlackBerry Z10 (White)
My Carrier: Vodafone

Re: Use MediaPlayer to repeat a song?

Just to add, you should use the RepeatMode enum in your call to setRepeatMode i.e: 

 

myPlayer.setRepeatMode(RepeatMode.Track);