Search code examples
iphoneobjective-ccocoa-touchuisliderexc-bad-access

iPhone UISlider crashing


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!


Solution

  • if(!(myAudio.totalTimeInBytes == 0.0f))
    {
         mySlider.value = (float)myAudio.packetPosition  / (float)myAudio.totalTimeInBytes;
    }
    else
    {
        mySlider.value = 0.0f; 
    }