From what i understand, loudspeakers require AC signals to cause an electromagnet to oscillate due to changes in current direction, thus force direction. How can this happen with a phone's battery/cell? shouldn't the battery only be capable of producing direct current?
Starting out from a speaker assembly, we need to generate a voltage that varies at the same rate as we want our membrane to vibrate and thus create sound. This problem also exists in AC powered devices, as the AC comes in at strictly a single frequency, which could generate only a single frequency of sound.
To do this, all digital devices use digital-to-analog (DAC) converters, almost always on a chip. They take some digital input signal at some of their pins, and output a voltage proportional to the value of that digital input on another pin. If we do this fast enough, i.e. feed different numbers in rapid succession, we will get a time-varying output signal.
If we happen to feed it input that corresponds to some audio signal we want to produce, and couple the output pin to a speaker, we are generating sound.
Edit: This is technically not yet alternating current, but AC on top of a DC signal. To get a real alternating current, the output of the converter can be connected through a capacitor (acting as a high-pass filter), which removes the DC part, so only AC can pass through.
How can this happen with a phone's battery/cell? shouldn't the battery only be capable of producing direct current?
First, let's address what is meant here by direct current since the term has different meanings according to context.
Direct current may mean unidirectional current which may be constant or time varying. A phone battery is (typically) rechargeable and so the battery current is not unidirectional nor is it constant.
Often, in electronic engineering, DC is a synonym for constant, e.g., a DC voltage source is a voltage source with constant voltage across. A battery is an approximation of a DC (constant) voltage source but the battery current is typically time varying depending on the load (and can be bidirectional as pointed out above).
Now, it's straightforward to generate a true AC (zero mean) signal with a circuit connected to a single DC (constant) power supply and there is more than one way to do this.
Here's an example (analog) circuit from a question at the Electrical Engineering stack exchange site:
This circuit is powered by a single DC power supply voltage (+Vs) and so, the output of the amplifier IC (pin 4) is always positive, i.e., it has non-zero mean (AKA, a DC offset). Connecting this output directly to a speaker would be a bad thing as speakers generally do not tolerate (significant) DC offset.
The solution is simple - drop the DC offset across a coupling capacitor (C7 in the schematic) so that the speaker sees only the AC portion of the output voltage at pin 4.
An entirely different approach is to create both positive and negative DC power supply voltages from the battery voltage using DC-DC converters. An amplifier with both positive and negative power supply voltages can produce true AC signals at the output so that a coupling capacitor is not required.