Skip to content

Commit

Permalink
fix(VideoPlayer): init videoPlayer after receiving source
Browse files Browse the repository at this point in the history
now video player starts after receiving source
  • Loading branch information
gevorg94 committed Nov 21, 2016
1 parent f49f8dd commit 3f3928a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
Binary file not shown.
46 changes: 25 additions & 21 deletions ios/RNVideoProcessing/RNVideoPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
//

import Foundation
import GPUImage
import AVFoundation
//import AVKit

@objc(RNVideoPlayer)
class RNVideoPlayer: RCTView {
Expand Down Expand Up @@ -43,8 +41,6 @@ class RNVideoPlayer: RCTView {
init(frame: CGRect, bridge: RCTBridge) {
super.init(frame: frame)
self.bridge = bridge

self.startPlayer()
}

required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -84,6 +80,7 @@ class RNVideoPlayer: RCTView {
set(val) {
if val != nil {
self._moviePathSource = val!
self.startPlayer()
}
}
get {
Expand All @@ -94,7 +91,7 @@ class RNVideoPlayer: RCTView {
// props
var currentTime: NSNumber? {
set(val) {
if val != nil {
if val != nil && player != nil {
let floatVal = val as! CGFloat
if floatVal <= self._playerEndTime && floatVal >= self._playerStartTime {
player.seek(to: CMTimeMakeWithSeconds(Float64(val!), Int32(NSEC_PER_SEC)))
Expand All @@ -119,11 +116,14 @@ class RNVideoPlayer: RCTView {
if self._playerStartTime > currentTime {
shouldBeCurrentTime = self._playerStartTime
}
player.seek(
to: convertToCMTime(val: shouldBeCurrentTime),
toleranceBefore: convertToCMTime(val: self._playerStartTime),
toleranceAfter: convertToCMTime(val: self._playerEndTime)
)

if player != nil {
player.seek(
to: convertToCMTime(val: shouldBeCurrentTime),
toleranceBefore: convertToCMTime(val: self._playerStartTime),
toleranceAfter: convertToCMTime(val: self._playerEndTime)
)
}
print("CHANGED startTime \(val)")
}
get {
Expand All @@ -145,11 +145,13 @@ class RNVideoPlayer: RCTView {
shouldBeCurrentTime = self._playerStartTime
}

player.seek(
to: convertToCMTime(val: shouldBeCurrentTime),
toleranceBefore: convertToCMTime(val: self._playerStartTime),
toleranceAfter: convertToCMTime(val: self._playerEndTime)
)
if player != nil {
player.seek(
to: convertToCMTime(val: shouldBeCurrentTime),
toleranceBefore: convertToCMTime(val: self._playerStartTime),
toleranceAfter: convertToCMTime(val: self._playerEndTime)
)
}
print("CHANGED endTime \(val)")
}
get {
Expand All @@ -159,7 +161,7 @@ class RNVideoPlayer: RCTView {

var play: NSNumber? {
set(val) {
if val == nil {
if val == nil || player == nil {
return
}
print("CHANGED play \(val)")
Expand Down Expand Up @@ -277,11 +279,13 @@ class RNVideoPlayer: RCTView {
if self.playerCurrentTimeObserver != nil {
self.player.removeTimeObserver(self.playerCurrentTimeObserver)
}
self.player.pause()
self.gpuMovie.cancelProcessing()
self.player = nil
self.gpuMovie = nil
print("CHANGED: Removing Oberver, that can be a cause of memory leak")
if player != nil {
self.player.pause()
self.gpuMovie.cancelProcessing()
self.player = nil
self.gpuMovie = nil
print("CHANGED: Removing Oberver, that can be a cause of memory leak")
}
}
}
/* @TODO: create Preview images before the next Release
Expand Down
1 change: 0 additions & 1 deletion ios/RNVideoProcessing/VideoProcessingGPUFilters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import GPUImage

class VideoProcessingGPUFilters {
let filters = [
Expand Down

0 comments on commit 3f3928a

Please sign in to comment.