Example 2 Given the function $f(x)=\frac{m-2 \sin x}{\cos x}$ is monotonically decreasing in the interval $\left(0, \frac{\pi}{2}\right)$, try to find the range of the real number $m$. Analysis We need to convert the expression into a relationship of the same trigonometric function. Here, we will use the universal formula.

Transform the expression above into English, keeping the original text's line breaks and format, and output the translation result directly.
Let $\tan \frac{x}{2}=t$, then $t \in(0,1)$. The original expression $=\frac{m-2 \cdot \frac{2 t}{1+t^{2}}}{\frac{1-t^{2}}{1+t^{2}}}=-m+\frac{2 m-4 t}{1-t^{2}}$
Assume $0\frac{m-2 t_{2}}{1-t_{2}^{2}}
$

Rearranging gives: $m2 \Leftrightarrow t_{1} t_{2}+1>t_{1}+t_{2} \Leftrightarrow\left(t_{1}-1\right)\left(t_{2}-1\right)>0
$

Since $t_{1}, t_{2} \in(0,1)$
The inequality holds. Thus, the value of $\frac{2 t_{1} t_{2}+2}{t_{1}+t_{2}}$ is $(2,+\infty)$, so $m \leqslant 2$ is required. Therefore, the range of $m$ is $(-\infty, 2]$.