Skip to content

Commit 1cc8b59

Browse files
author
xianing
committed
resolve player remain issues
1 parent 2e865bb commit 1cc8b59

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/MediaPlayer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static io.agora.mediaplayer.Constants.MediaPlayerState.PLAYER_STATE_IDLE;
3939
import static io.agora.mediaplayer.Constants.MediaPlayerState.PLAYER_STATE_OPEN_COMPLETED;
4040
import static io.agora.mediaplayer.Constants.MediaPlayerState.PLAYER_STATE_PLAYBACK_COMPLETED;
41+
import static io.agora.mediaplayer.Constants.MediaPlayerState.PLAYER_STATE_STOPPED;
4142
import static io.agora.rtc2.video.VideoCanvas.RENDER_MODE_HIDDEN;
4243
import static io.agora.rtc2.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
4344
import static io.agora.rtc2.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
@@ -517,8 +518,11 @@ public void onPlayerStateChanged(io.agora.mediaplayer.Constants.MediaPlayerState
517518
Log.e(TAG, "onPlayerStateChanged mediaPlayerError " + mediaPlayerError);
518519
if (mediaPlayerState.equals(PLAYER_STATE_OPEN_COMPLETED)) {
519520
setMediaPlayerViewEnable(true);
520-
} else if (mediaPlayerState.equals(PLAYER_STATE_IDLE) || mediaPlayerState.equals(PLAYER_STATE_PLAYBACK_COMPLETED) ) {
521+
} else if (mediaPlayerState.equals(PLAYER_STATE_IDLE) || mediaPlayerState.equals(PLAYER_STATE_STOPPED) || mediaPlayerState.equals(PLAYER_STATE_PLAYBACK_COMPLETED) ) {
521522
setMediaPlayerViewEnable(false);
523+
options.publishMediaPlayerVideoTrack = false;
524+
options.publishMediaPlayerAudioTrack = false;
525+
engine.updateChannelMediaOptions(options);
522526
}
523527
}
524528

iOS/APIExample/Examples/Advanced/MediaPlayer/Base.lproj/MediaPlayer.storyboard

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19162" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="System colors in document resources" minToolsVersion="11.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -114,19 +114,26 @@
114114
</connections>
115115
</button>
116116
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="uBn-Om-6Vs">
117-
<rect key="frame" x="165" y="0.0" width="32" height="30"/>
117+
<rect key="frame" x="103" y="0.0" width="32" height="30"/>
118118
<state key="normal" title="Stop"/>
119119
<connections>
120120
<action selector="doStopWithSender:" destination="jxp-ZN-2yG" eventType="touchUpInside" id="zJg-By-NUx"/>
121121
</connections>
122122
</button>
123123
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gpl-j7-fNe">
124-
<rect key="frame" x="332" y="0.0" width="42" height="30"/>
124+
<rect key="frame" x="208" y="0.0" width="42" height="30"/>
125125
<state key="normal" title="Pause"/>
126126
<connections>
127127
<action selector="doPauseWithSender:" destination="jxp-ZN-2yG" eventType="touchUpInside" id="r75-hp-PgR"/>
128128
</connections>
129129
</button>
130+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vfb-Ay-x4e">
131+
<rect key="frame" x="323" y="0.0" width="51" height="30"/>
132+
<state key="normal" title="Publish"/>
133+
<connections>
134+
<action selector="doPublishWithSender:" destination="jxp-ZN-2yG" eventType="touchUpInside" id="cuV-Ma-rDj"/>
135+
</connections>
136+
</button>
130137
</subviews>
131138
</stackView>
132139
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Playout Volume" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nDn-o2-Vmd">

iOS/APIExample/Examples/Advanced/MediaPlayer/MediaPlayer.swift

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ class MediaPlayerMain: BaseViewController, UITextFieldDelegate {
178178

179179
@IBAction func doPlay(sender: UIButton) {
180180
mediaPlayerKit.play()// get channel name from configs
181+
}
182+
183+
@IBAction func doStop(sender: UIButton) {
184+
mediaPlayerKit.stop()
185+
}
186+
187+
@IBAction func doPause(sender: UIButton) {
188+
mediaPlayerKit.pause()
189+
}
190+
191+
@IBAction func doPublish(sender: UIButton) {
181192
guard let channelName = configs["channelName"] as? String else { return }
182193
let option = AgoraRtcChannelMediaOptions()
183194
option.publishMediaPlayerVideoTrack = .of(true)
@@ -188,14 +199,7 @@ class MediaPlayerMain: BaseViewController, UITextFieldDelegate {
188199
connection.channelId = channelName
189200
connection.localUid = PLAYER_UID
190201
agoraKit.updateChannelEx(with: option, connection: connection)
191-
}
192-
193-
@IBAction func doStop(sender: UIButton) {
194-
mediaPlayerKit.stop()
195-
}
196-
197-
@IBAction func doPause(sender: UIButton) {
198-
mediaPlayerKit.pause()
202+
199203
}
200204

201205
@IBAction func doAdjustPlayoutVolume(sender: UISlider) {
@@ -292,20 +296,28 @@ extension MediaPlayerMain: AgoraRtcMediaPlayerDelegate {
292296
LogUtils.log(message: "player rtc channel publish helper state changed to: \(state.rawValue), error: \(error.rawValue)", level: .info)
293297
DispatchQueue.main.async {[weak self] in
294298
guard let weakself = self else { return }
295-
switch state {
296-
case .failed:
299+
switch state.rawValue {
300+
case 100: // failed
297301
weakself.showAlert(message: "media player error: \(error.rawValue)")
298302
break
299-
case .openCompleted:
303+
case 2: // openCompleted
300304
let duration = weakself.mediaPlayerKit.getDuration()
301305
weakself.playerControlStack.isHidden = false
302306
weakself.playerDurationLabel.text = "\(String(format: "%02d", duration / 60000)) : \(String(format: "%02d", duration % 60000 / 1000))"
303307
weakself.playerProgressSlider.setValue(0, animated: true)
304308
break
305-
case .stopped:
309+
case 7: // stopped
306310
weakself.playerControlStack.isHidden = true
307311
weakself.playerProgressSlider.setValue(0, animated: true)
308312
weakself.playerDurationLabel.text = "00 : 00"
313+
guard let channelName = weakself.configs["channelName"] as? String else { return }
314+
let option = AgoraRtcChannelMediaOptions()
315+
option.publishMediaPlayerVideoTrack = .of(false)
316+
option.publishMediaPlayerAudioTrack = .of(false)
317+
let connection = AgoraRtcConnection()
318+
connection.channelId = channelName
319+
connection.localUid = PLAYER_UID
320+
weakself.agoraKit.updateChannelEx(with: option, connection: connection)
309321
break
310322
default: break
311323
}

iOS/APIExample/Examples/Advanced/MediaPlayer/zh-Hans.lproj/MediaPlayer.strings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@
3737

3838
/* Class = "UIButton"; normalTitle = "Play"; ObjectID = "vdv-zd-3aD"; */
3939
"vdv-zd-3aD.normalTitle" = "播放";
40+
41+
42+
/* Class = "UIButton"; normalTitle = "Publish"; ObjectID = "vfb-Ay-x4e"; */
43+
"vfb-Ay-x4e.normalTitle" = "发流";

0 commit comments

Comments
 (0)