solution of a ODE with a funtion of $\dot{x}$

I have the equation:
with m, k as constants and $$A = \left\{
a & : \dot{x}(t) <0\\
-a & : \dot{x}(t) >0
\right. $$
a another constant. My question is how to solve for x(t) since A is a function of $\dot{x}(t)$ making it nonlinear.

Solutions Collecting From Web of "solution of a ODE with a funtion of $\dot{x}$"

The solution has the form $x(t)=C·\sin(ω t+φ)\pm D$ with $D=a/k$ and $ω^2=k/m$. The derivative is $x(t)=Cω·\cos(ω t+φ)$ and the condition for any solution is continuity of function and first derivative. Thus at any point where the derivative switches sign from negative to positive we need to satisfy for continuous derivative
ω t+φ_1=-\frac\pi2+2k_1\pi,\;ω t+φ_2=-\frac\pi2+2k_2\pi\implies φ_2-φ_1=2k\pi
or wlog $φ_2=φ_1=φ$. And for simple continuity
or $C_2=C_1-2D$.

At a change from positive to negative derivative we need $ω t+φ=\frac\pi2+2k\pi$ and
or again $C_2=C_1-2D$.

That repeats as long as $C_2$ stays positive. Now if $0<C_1<2D$ there is, it seems, no continuation possible.

Or to make it more geometrical: The pair $(ω·x(t),x'(t))$ follows a circle equation since
ω^2·(x+D)^2+(x’)^2=\text{const. for }x’>0,\text{ i.e., in the upper half plane}
ω^2·(x-D)^2+(x’)^2=\text{const. for }x'<0,\text{ i.e., in the lower half plane}
moving clockwise. The radius reduction by $2D$ on the horizontal axis results in an inward spiral pattern. Until after a finite time there is no continuation possible.

For numerical experiments try the smoothed approximation
$\varepsilon=10^{-2}$ allows for non-singular solutions, $\varepsilon=10^{-6}$ gives the step-size controller a workout.

The behavior of the solution of this kind of ODEs has been examined in great detail in the framework of sliding-mode control theory. My suggestion is to read the paper

J. Cortes ,”Discontinuous dynamical systems,” IEEE Control Systems Magazine, 28(3), 36-73, 2008 (there is an arxiv version that you can download).

This is actually an ODE system with discontinuous right hand side. Therefore, generalized solutions in the sense of Fillipov should be considered. Even though the complete solution(s) is not obvious to me, their properties can in fact be deduced. For example, one can prove that $\lim_{t\rightarrow\infty}\dot{x}(t)=0$ and $\lim_{t\rightarrow\infty}x(t)=c$ for some $c\in\mathbb{R}$ assuming $k,m,a>0$.

This is obtained as follows:

From the fact that $\frac{d}{dt}\bigg[\frac{m}{2}\dot{x}^2+\frac{k}{2}x^2+a\int_0^t{|\dot{x}(s)|ds}\bigg]=0$ we conclude that $x\in L_{\infty}$ and $\dot{x}\in L_{\infty}\cap L_{1}$. Then from the original equation $\ddot{x}$ is also bounded. Now Barbalat lemma can be applied to prove $\lim_{t\rightarrow\infty}\dot{x}(t)=0$. Thus, $\lim_{t\rightarrow\infty}x^2(t)=x^2(0)+\frac{m}{k}\dot{x}^2(0)-\frac{2a}{k}\int_0^{\infty}{|\dot{x}(s)|ds}:=c$.