-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Player shows a black screen while playing video on IOS #1029
Comments
Working on real device. Tested on iPhone 7 plus. |
Same problem here. With iOS simulator the screen remains black but I can hear the audio as the video progresses. I have tested different versions of this library. Version 0.0.69 is the highest version that has worked for me, it does not display a black screen but the actual video, so it seems the right behavior. The steps I followed to try is (in AndroidStudio + Terminal):
I've been looking the changes related to iOS between version 0.0.69 and 0.0.70 and they seem quite a lot, so finding the offending piece of code may take its time. I add the link here in case anyone wants to take a look in parallel. |
I dig deeper in every commit between version 0.0.69 and 0.0.70 to find the offending commit. What I found is that Then, the changes that impact on the iOS simulator visualization are those of commit To reproduce the working commit just add the following to your pubspect.yaml:
And then, follow the steps of the code snipped in my previous comment. Here you can find the changes of the offending commit. This bounds a little more the problem, let's check if we can find the problem with this. :) |
It seems, that the commit in the previous comment is divided in 15 commits, so I analyzed them and the last subcommit that works is The changes of this commit can be change here. Now the problem seems quite bounded and the changes of this commit are small, I can try to roll back those changes in version 0.0.83 just to check if this solves the problem. :) |
By rolling back the changes I am able to see the video (no black screen) on version 0.0.83. I uploaded the changes to my fork of the repository, so you can try if it is the same problem for you too. To test with my fork you can use:
However, this commit is just for testing purposes, as it just rollbacks some changes without taking into account the implications of that and produces a segmentation faults. I uploaded the commit just to verify that the problem of other people is caused by the same code, and if so we can focus on fixing that code, so I will be glad if some of you can verify that black screen problem disappears on iOS simulator using my fork. @koldo92, I see that you are the committer of that code, do you remember what problem it was trying to fix? I see that the changes are related with |
Doing some research it seems that the reason of the change is explained in this comment. So it seems a way to fix black screen problem on Android and iOS by using UIKit instead of Texture on iOS devices, however, this same solution causes iOS simulator to show black screen. Let's research more to see if it is possible to have both iOS simulator and devices working. 😄 |
The plugin native_video_view seems to display correctly in the simulator, and its approach is similar to the one used after commit I tried, WITH NO SUCCESS, to replicate their code by adding a create view method in - (void)createView:(CGRect)frame {
if (_playerView == nil || _playerView == NULL || [_playerView.class isKindOfClass:NSNull.class]) {
_playerView = [[BetterPlayerView alloc] initWithFrame:frame];
}
_playerView.backgroundColor = [UIColor clearColor];
_playerView.player = _player;
AVPlayerLayer* playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
if (playerLayer != nil) {
playerLayer.frame = [_playerView bounds];
playerLayer.videoGravity = AVLayerVideoGravityResize;
_playerView.layer.sublayers = nil;
[_playerView.layer addSublayer:playerLayer];
}
} And called in #pragma mark - FlutterPlatformViewFactory protocol
- (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
viewIdentifier:(int64_t)viewId
arguments:(id _Nullable)args {
NSNumber* textureId = [args objectForKey:@"textureId"];
BetterPlayer* player = [_players objectForKey:@(textureId.intValue)];
[player createView:frame];
return player;
} I will continue the research and posting here the things that I find, just in case anyone else wants to help debugging this issue too. Thank you all! :D |
Ok, I have some good news. I am able to visualize videos on iOS simulator just by disabling video composition. (void)setDataSourcePlayerItem:(AVPlayerItem*)item withKey:(NSString*)key{
...
#if !TARGET_OS_SIMULATOR
item.videoComposition = videoComposition;
#endif
...
} It seems that the iOS simulator is not rendering the image successfully when running on simulator. Even if this solution fixes the problem I prefer to find a solution which does not branch the behavior if it runs in the simulator. As it can make future bugs harder to debug. @jhomlala what is the objective of using |
Finally I push a fix to my personal fork of this project. The changes I did can be seen in this commit. I plan to do a pull request to this repository, but only when several people have tested on their simulators and physical devices to verify that I did not break anything. In my iOS simulator and iPhone 11 it works correctly. The changes introduced by this commit removes the correction of video track transform, that was used previously to fix black screen problems on iOS devices. Contrary to the proposed in my previous comment, I removed the correction for both iOS simulatior and physical device, as my assumption is that the fix was required due to the previous usage of In order to use my personal fork you can add the following dependency to your better_player:
git:
url: https://github.com/marioloko/betterplayer.git
ref: ios-simulator-blackscreen If you experience any issue with the given solution please tell me to fix it. And if you test it and it works for you, please add a comment about which platform did you run it (iOS simulator, iPhone, iPad), just to verify that the solution works for these platforms. This solution works for me, so I do not plan to do further research unless any of you find a problem with the proposed solution, in that case I will try to solve the issue. 😄 |
@marioloko thank you so much for the temporary fix. let me try it out and hope it will work great for me |
Thank you for testing the solution. Can you comment here if worked fine for you or experience any problem? |
it still doesn't work on 0.0.81 with flutter v2.10.5 |
@marioloko It worked for me. Any predictions to enter the major version? |
My commit is only committed in my fork, right now it is not available in the main repo.
If it worked for you I will open a pull request to the main repository. But I cannot tell you for sure when it will be accepted. |
@jhomlala can you accept the pull request to merge the fix to the main branch? |
@marioloko have you test it in real device IOS 16+ for .m3u8 videos? |
I tested on my iPhone but not for .m3u8 so I can't tell if my repo will work, but you can try pointing to it. |
I tested this branch in a ios and android simulator and also in a ios and android devices. The fix of the black screen works great, it would be great a release with this fix. The only issue that i found is that the dot of the progress bar doesn't move while the video is playing. It gets stuck. I going to check if this is happening in the actual release. |
Thanks for your work.
|
I don't think so, because when you use a import a library in your dart code you are importing one version of the code, so with two refs ai think dart will not be able to resolv which version of the code to use. What do you need to achieve? Two fixes? The solution for that should be to merge both fixes in a single branch, in case the branches do not conflict I do not mind to create a branch merging both branches, but I will not be able to test it, so you will have to test it works. |
History check
Looking at past issues, someone suggested they experienced the issue but no solution. He suggested its an issue in better_player: ^0.0.81, and suggested a change to 0.0.80 but this doesn't work.
Describe the bug
The player is able to load the network video but only the audio plays. the video doesn't show. All though.
To Reproduce
Ive experienced the issue with a video from network and not quite certain if other types also produce the same. Since my app only uses videos from network.
*Example code
Expected behavior
The video loads and plays but keeps showing a black screen.
Screenshots
Flutter doctor
Better Player version
better_player: ^0.0.81
Smartphone (please complete the following information):
The text was updated successfully, but these errors were encountered: