SCRecorder icon indicating copy to clipboard operation
SCRecorder copied to clipboard

SCPlayer sometimes just show black screen, but the sound works fine.

Open albertgh opened this issue 10 years ago • 43 comments
trafficstars

After I use [self.player setItemByUrl:[NSURL fileURLWithPath:videoPath]]; to setItem, and make self.player.shouldSuppressPlayerRendering = NO;, black screen are getting less, but still happens sometime.

albertgh avatar Nov 17 '15 07:11 albertgh

+1 experiencing this sometimes as well, I'll take a look over the next few days.

twomedia avatar Nov 17 '15 08:11 twomedia

I have been looking into this for two days, can't figure out why...

I moved it into viewWillAppear: as sample, but still happens.

albertgh avatar Nov 20 '15 11:11 albertgh

Here's an easy fix for this, just nuke the filters. This obsession with photo and video filters for everything is pretty dumb if you ask me, so here's the nuke em' solution:

in SCVideoPlayerViewController.m

change the the ENTIRE viewDidLoad method to this:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.exportView.clipsToBounds = YES;
    self.exportView.layer.cornerRadius = 20;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveToCameraRoll)];
    _player = [SCPlayer player];
    SCVideoPlayerView *playerView = [[SCVideoPlayerView alloc] initWithPlayer:_player];
    playerView.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    playerView.frame = self.filterSwitcherView.frame;
    playerView.autoresizingMask = self.filterSwitcherView.autoresizingMask;
    [self.filterSwitcherView.superview insertSubview:playerView aboveSubview:self.filterSwitcherView];
    [self.filterSwitcherView removeFromSuperview];
    _player.loopEnabled = YES;
}

Then, you won't have that silly blackscreen anymore. This is tested on iphone 6s+ with 128 GB of memory running the latest IOS 9.1

EDIT

One more quick fix, hold up, I gutted too much, this does do away with the blackscreen but I accidently killed the editing button, one sec

... Okay, it works now, just nuke the viewdidload like I show above and it's fixed, I'd also disable the loopenabled and just jump right to the editing screen.

ghost avatar Nov 20 '15 23:11 ghost

@jimmykrinkles Yes, kill filter do fix blackscreen. But i do need filter, it seems something wrong with SCFilterSwitcherView.

When I got a blackscreen, layoutSubviews in SCFilterSwitcherView only print twice. When filter works fine, layoutSubviews in SCFilterSwitcherView print thrice.

albertgh avatar Nov 23 '15 08:11 albertgh

I fixed it by calling unsetupDisplayLink followed by setupDisplayLink whenever I set a new item to play

CristianoCastroNabia avatar Nov 30 '15 11:11 CristianoCastroNabia

@CristianoCastroNabia

I tried reset CIImageRenderer, should works same as your way, but still got blackscreen.

self.player.CIImageRenderer = nil;
self.player.CIImageRenderer = self.containerView.filterSwitcherView;

albertgh avatar Nov 30 '15 12:11 albertgh

You should also just shut off Metal rendering since the author of this library doesn't know a damn thing about rendering with Metal. Turning off metal should fix a lot. When I say turn it off, just gut everything that is Metal related. The way the textures are set up with Metal is wrong, even though many people are having the same Metal errors that this library has. There's a right way to do this and this library doesn't employ the textures correctly, not even close to correctly, so disabling this part will help you out, or you can just redevelop the Metal rendering the correct way. Either way, you'll notice that the first check on the device compatibility check is to check if the device can handle Metal, if it can, then Metal is chosen, so turning this off helps since the Metal in this library isn't even close to correct.

ghost avatar Nov 30 '15 14:11 ghost

The Metal part shouldn't be used by default anyway. Is it true I know little to nothing about it (just quickly went through for iOS 9), I just followed one example that Apple gave (which doesn't seem to work on iOS 9.1). You are very welcome to help me out with that since you are such an expert.

Regarding the black screen issue: Are you reusing the player? When that happens, can you tell me the status of the following:

  • is the displayLink being set? what's the value of its "paused" property? Is willRenderFrame: being called?

You should also update the library since it appears you are using an older version (CIImageRenderer has been replaced by SCImageView for instance).

rFlex avatar Dec 03 '15 14:12 rFlex

@rFlex Thanks for your library.

I use 2.5.3 because I need to support iOS 7.x.

I did nothing with displayLink, I only do setItemByAsset:,

I did call [self.player pause] before setItem, and do play after setItem.

I have checked willRenderFrame is being called.

albertgh avatar Dec 04 '15 11:12 albertgh

@albertgh 你黑屏解决了吗,我也遇到了,和player有关系,普通的avplayer就没问题。。

kaka1220 avatar Dec 10 '15 08:12 kaka1220

Any update on this? @albertgh Were you able to fix an issue somehow?

ren6 avatar Feb 12 '16 18:02 ren6

@ren6 Sorry I still can't figure out, I just disable the filters for now.

albertgh avatar Feb 13 '16 05:02 albertgh

@omergul123 any clue on how to fix this?

moofaces avatar Feb 13 '16 23:02 moofaces

@albertgh I was facing the same issue, the thing is SCPlayer setItemWithURL seems not to work properly. I've tested in the example project and the black screen problem appears. I'm using setItemByAsset instead and it works perfectly. Hope it helps

glm4 avatar Feb 15 '16 18:02 glm4

@sherm4n90 are you using it with the filters and it's working fine for you? And is there any limitations taking that out?

moofaces avatar Feb 15 '16 20:02 moofaces

@moofaces Yes, Im using the SCSwipeableFiltersView and it works great. No limitations, you just need to change your code to supply an SCRecordSession.assetRepresentingSegments to the SCPlayer and it should work.

glm4 avatar Feb 16 '16 12:02 glm4

@sherm4n90 This doesn't make sense because setItemWithURL: calls setItemByAsset: I think the problem still appears for you or you have fixed it another way.

ren6 avatar Feb 16 '16 13:02 ren6

@ren6 You are right, what I mean is the problem should be at setting an usual asset and not an asset from a SCRecordSession created with - (AVAsset *)assetRepresentingSegments. I tried any possible solution and no success when using AVasset or url asset by myself. After figure out the problem I tried by creating a SCSessionRecord, add a SCRecordSessionSegment with my URL and then use SCRecordSession.assetRepresentingSegments and it also works fine(if you can't use the SCRecorder or just don't want this may be your solution) . Hope it helps.

glm4 avatar Feb 16 '16 13:02 glm4

@sherm4n90, are you saying we shouldn't see the issue if we are using a SCSessionRecord.assetRepresentingSegments for the player? I'm attempting this but only seeing a black screen, though my issue might be different from others as I also have no audio.

Edit: If I add the filter to my recorder instead of the preview after done recording, I get audio with a black screen.

ayurkows avatar Feb 16 '16 18:02 ayurkows

@ayurkows Yes, that is what I mean. As I said before I've tried with an URL asset in the provided example and the black screen appears. For the audio only issue check the SCRecorder delegate responses, it has some methods that may result useful.

glm4 avatar Feb 16 '16 20:02 glm4

@rFlex I was finally able to see the black screen hooked to the debugger. the most interesting thing I found was: (pretend these are CMTime comparisons) recordedSession.duration.seconds > 0 but player.playableDuration.seconds == 0

so it seems like player.setItemByAsset(recordedSession.assetRepresentingSegments()) is somewhere along the line creating a bad asset item. (mine is called in will appear)

recordedSession.assetRepresentingSegments() worked in the debugger but it barfed on AVPlayerItem(asset:recordedSession.assetRepresentingSegments())

Interestingly I have a button on screen that brings up a modal. Dismissing that fires will appear again and my recordedSession plays fine no more black screen.

aprato avatar Feb 26 '16 21:02 aprato

Anyone ever figure this out?

I'm experiencing the same thing but it is very hard to reproduce. It seems to happen more often on the iPhone 6 Plus. It happens to me about 10% of the time, but I've had other iPhone 6 Plus users report it happening as much as 30% of the time.

mitchellporter avatar Apr 07 '16 06:04 mitchellporter

I got this issue whenever I'm recording and have a comming call

levantAJ avatar Apr 07 '16 06:04 levantAJ

@levantAJ That's a predictable issue and expected because it has to do with the shared audio session of your device. What I described, and what others have described above, is a much trickier issue that should not be happening.

I think it may have something to do with setting the videoConfiguration's filter property before/while recording, but I'm honestly not sure and that's just a random guess.

mitchellporter avatar Apr 07 '16 06:04 mitchellporter

Edit: I saw fewer black screens, but this did not solve the issue when the app moved to QA.

I've had some success so far with the following method:

  • Before adding SCSwipeableFilterView to a player's SCImageView, I set shouldSuppressPlayerRendering to false.
  • Later in the lifecycle (but before the view appears, I chose viewWillAppear), I set shouldSuppressPlayerRendering to true.

This seemed to be a workaround for me, and seemed to consistently work in development. Will update on this issue during QA and testing. I'll take a deeper dive soon.

alihen avatar May 16 '16 11:05 alihen

@alihen This sounds interesting! I ended up just removing the filters altogether because analytics showed that users preferred our basic image filters, but I'd still love to find a fix for this issue.

Please keep us updated and let us know if that truly fixes it.

mitchellporter avatar May 17 '16 00:05 mitchellporter

After doing some digging, I found that the issue is independent of using AVAsset or a URL (both are used as an AVAsset).

What I have found is that this is most likely caused by a race condition relating to the rendering of SCSwipeableFilterView. A workaround was to suppress the player rendering, and then enable player rendering once the view had appeared. In order to do this, I used a simple timer (This is quite hacky, but has shown better results - 100% in dev), but you're welcome to use other methods.

func setupVideo(){
   ...
   self.view.alpha = 0 // Set to alpha to 0 to prevent flashing of screen
   self.player.shouldSuppressPlayerRendering = false
   ... // Set up player as you would.
}

override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)   
        NSTimer.scheduledTimerWithTimeInterval(0.3, target: self, selector: #selector(ViewController.enableFilterRendering), userInfo: nil, repeats: false)
       // I set the timer to 0.3 seconds, leaving enough time for the offending method to complete.
 }

func enableFilterRendering() {
        if !self.player.shouldSuppressPlayerRendering{
            self.player.shouldSuppressPlayerRendering = true
            UIView.animateWithDuration(0.1, animations: {
                self.view.alpha = 1
            })
        }
}

Really want to get to be bottom of this issue when I have some free time, but for now this will have to do. Hope this helps @rFlex and others.

alihen avatar May 18 '16 14:05 alihen

I may have fixed the issue yesterday. Could you please try again with the latest version? It's not on cocoapods yet though.

rFlex avatar May 18 '16 15:05 rFlex

@rFlex, tested master with a basic sample and still seeing the issue, although maybe a bit less frequently.

alihen avatar May 18 '16 15:05 alihen

Any fix for this? Unfortunately we're using this pod specifically for CIFilters with videos. Seeing black image about 60-70% of the time on iPhone 6.

mourlamstudios avatar Jun 01 '16 02:06 mourlamstudios