@@ -12,6 +12,7 @@ class MainContainer extends Component {
12
12
snapshotIndex : 0 ,
13
13
currentIndex : null ,
14
14
port : null ,
15
+ playing : false ,
15
16
} ;
16
17
this . handleChangeSnapshot = this . handleChangeSnapshot . bind ( this ) ;
17
18
this . handleSendSnapshot = this . handleSendSnapshot . bind ( this ) ;
@@ -64,13 +65,21 @@ class MainContainer extends Component {
64
65
65
66
playForward ( ) {
66
67
var play = setInterval ( ( ) => {
67
- const { snapshots, snapshotIndex } = this . state ;
68
- if ( snapshotIndex < snapshots . length - 1 ) {
69
- const newIndex = snapshotIndex + 1 ;
70
- this . handleJumpSnapshot ( newIndex ) ;
71
- this . setState ( { snapshotIndex : newIndex } ) ;
72
- } else clearInterval ( play ) ;
68
+ const { snapshots, snapshotIndex, playing } = this . state ;
69
+ if ( ! playing ) {
70
+ if ( snapshotIndex < snapshots . length - 1 ) {
71
+ const newIndex = snapshotIndex + 1 ;
72
+ this . handleJumpSnapshot ( newIndex ) ;
73
+ this . setState ( { snapshotIndex : newIndex , playing : true } ) ;
74
+ } else {
75
+ this . setState ( { playing : false } )
76
+ clearInterval ( play ) ;
77
+ }
78
+ } else {
79
+ clearInterval ( play ) ;
80
+ }
73
81
} , 1000 )
82
+
74
83
play ( ) ;
75
84
}
76
85
@@ -124,7 +133,7 @@ class MainContainer extends Component {
124
133
}
125
134
126
135
render ( ) {
127
- const { snapshots, snapshotIndex } = this . state ;
136
+ const { snapshots, snapshotIndex, playing } = this . state ;
128
137
return (
129
138
< div className = "main-container" >
130
139
< HeadContainer />
@@ -145,6 +154,7 @@ class MainContainer extends Component {
145
154
moveBackward = { this . moveBackward }
146
155
moveForward = { this . moveForward }
147
156
playForward = { this . playForward }
157
+ playing = { playing }
148
158
/>
149
159
</ div >
150
160
</ div >
0 commit comments