You call this getTrack(1) with or without an audio track present (here and in other places). If there's no audio track present, the only track is the video track which would be 0.

Just store pointers to the two different tracks instead of calling getTrack().