What is the oxidation number of the oxygen in BaO2
"oxygen always -2 except in peroxides"


This exception is in effect here, because $\ce{BaO2}$ is a peroxide consisting of $\ce{Ba^{2+}}$ and $\ce{O2^{2-}}$ ions. The oxidation number of Ba is +II, and the oxidation number of each of the oxygens in the peroxide anion is -I. This fits with the charge of the peroxide anion ($2 \times -1 = -2$), and as $\ce{BaO2}$ is a neutral compound, the sum of all oxidation numbers is 0. Moreover, there are even more exceptions to the rule of thumb cited above, for example, the superoxide radical anion $\ce{O2-}$ with a fractional oxidation numer of $-\frac{1}{2}$, or the dioxygenyl cation $\ce{O2+}$ with a formal oxidation number of $+\frac{1}{2}$ for each oxygen.

In contrast to peroxides, "simple ionic compounds" of oxygen are oxides, which contain the anion $\ce{O^{2-}}$. The charge of the oxide anion is $2-$, so the oxidation number of oxygen in those compounds is -II.