0

I have an UISlider that shows the progress of a song, and the user can go back and forth using it.

I'm using a custom player an the code for my UISlider is the following:

mySlider.value = (float)myAudio.packetPosition  / (float)myAudio.totalTimeInBytes;

All works perfectly but sometimes the application crashes, receiving a EXC_BAD_ACESS. Maybe it's a division by zero, I don't know.

How do I prevent this?

Thank you!

neowinston
  • 7,584
  • 10
  • 52
  • 83

1 Answers1

0
if(!(myAudio.totalTimeInBytes == 0.0f))
{
     mySlider.value = (float)myAudio.packetPosition  / (float)myAudio.totalTimeInBytes;
}
else
{
    mySlider.value = 0.0f; 
}
Fran Sevillano
  • 8,103
  • 4
  • 31
  • 45