所谓静音,就是没有声音,把音量调到最小不就好了。所以,只要调节音量就行。那么,这样就很简单了,系统给我们提供了属性啊。
在AVPlayer中,有属性
@property (nonatomic) float volume NS_AVAILABLE(10_7, 7_0);
看注释:
/* Indicates the current audio volume of the player; 0.0 means "silence all audio", 1.0 means "play at the full volume of the current item".
iOS note: Do not use this property to implement a volume slider for media playback. For that purpose, use MPVolumeView, which is customizable in appearance and provides standard media playback behaviors that users expect.
This property is most useful on iOS to control the volume of the AVPlayer relative to other audio output, not for volume control by end users. */
所以:
关: self.avPlayer.volume = 0.0;
开: self.avPlayer.volume = 1.0;