@@ -12,6 +12,7 @@ @interface View ()
1212{
1313 Media::PlaybackManager* _manager;
1414 NSBitmapImageRep * _currentFrame;
15+ NSString * _errorMessage;
1516}
1617@end
1718
@@ -52,6 +53,27 @@ - (void)setPlaybackManager:(Media::PlaybackManager*)manager
5253 if (strong_self) {
5354 auto * ns_frame = ns_from_gfx (move (frame));
5455 strong_self->_currentFrame = ns_frame;
56+ strong_self->_errorMessage = nil ;
57+ [strong_self setNeedsDisplay: YES ];
58+ }
59+ };
60+
61+ _manager->on_decoder_error = [weak_self](auto error) {
62+ View* strong_self = weak_self;
63+ if (strong_self) {
64+ auto error_string = error.description ();
65+ strong_self->_currentFrame = nil ;
66+ strong_self->_errorMessage = [NSString stringWithFormat: @" Decoder error: %.*s " , (int )error_string.length (), error_string.characters_without_null_termination ()];
67+ [strong_self setNeedsDisplay: YES ];
68+ }
69+ };
70+
71+ _manager->on_fatal_playback_error = [weak_self](auto const & error) {
72+ View* strong_self = weak_self;
73+ if (strong_self) {
74+ auto error_string = error.string_literal ();
75+ strong_self->_currentFrame = nil ;
76+ strong_self->_errorMessage = [NSString stringWithFormat: @" Fatal playback error: %.*s " , (int )error_string.length (), error_string.characters_without_null_termination ()];
5577 [strong_self setNeedsDisplay: YES ];
5678 }
5779 };
@@ -64,6 +86,23 @@ - (void)drawRect:(NSRect)rect
6486 [[NSColor blackColor ] setFill ];
6587 NSRectFill (rect);
6688
89+ if (_errorMessage) {
90+ NSFont * font = [NSFont preferredFontForTextStyle: NSFontTextStyleTitle1 options: @{}];
91+
92+ NSMutableParagraphStyle * paragraph_style = [[NSMutableParagraphStyle defaultParagraphStyle ] mutableCopy ];
93+ paragraph_style.alignment = NSTextAlignmentCenter;
94+
95+ NSRect bounding_rect = self.bounds ;
96+ bounding_rect.size .height *= 0.66 ;
97+
98+ [_errorMessage drawInRect: bounding_rect
99+ withAttributes: @{
100+ NSFontAttributeName : font,
101+ NSForegroundColorAttributeName : [NSColor whiteColor ],
102+ NSParagraphStyleAttributeName : paragraph_style,
103+ }];
104+ }
105+
67106 if (!_currentFrame)
68107 return ;
69108
0 commit comments