An electronic device integrating an earphone and a loudspeaker comprises a processor, an interface unit, a first switch, an earphone drive unit, a loudspeaker drive unit, a sound play unit, a second switch and a detection unit. The second switch is accordingly switched on or switched off according to whether the sound play unit is placed in an electronic device body or not. The detection unit accordingly generates a detection signal according to the on-off state of the second switch. The processor plays an audio signal with the regulated play power by accordingly controlling the first switch through the interface unit to be switched so as to be connected with the earphone drive unit or the loudspeaker drive unit and by transmitting the audio signal to the connected earphone drive unit or the connected loudspeaker drive unit through the interface unit. According to the electronic device, the technical problem that in the prior art, due to the fact that sound play modes are switched by frequently plugging and pulling the earphone, operation is not convenient is solved by moving the sound play unit into or out of the electronic device body so as to select the audio play signal of the earphone or the loudspeaker.