VLCMainWindow.m 23.9 KB
Newer Older
1
/*****************************************************************************
2
 * VLCMainWindow.m: MacOS X interface module
3
 *****************************************************************************
4
 * Copyright (C) 2002-2018 VLC authors and VideoLAN
5 6 7
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8 9 10
 *          Jon Lech Johansen <jon-vl@nanocrew.net>
 *          Christophe Massiot <massiot@via.ecp.fr>
 *          Derk-Jan Hartman <hartman at videolan.org>
11
 *          David Fuhrmann <david dot fuhrmann at googlemail dot com>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

28 29
#import "VLCMainWindow.h"

30
#import "VLCMain.h"
31
#import "CompatibilityFixes.h"
32
#import "VLCCoreInteraction.h"
33
#import "VLCAudioEffectsWindowController.h"
34
#import "VLCMainMenu.h"
35
#import "VLCOpenWindowController.h"
36
#import "VLCPlaylist.h"
37
#import <math.h>
38
#import <vlc_playlist.h>
39 40
#import <vlc_url.h>
#import <vlc_strings.h>
41
#import <vlc_services_discovery.h>
42
#import "VLCPLModel.h"
43

44
#import "VLCMainWindowControlsBar.h"
45
#import "VLCVoutView.h"
46
#import "VLCVideoOutputProvider.h"
47

48
@interface VLCMainWindow() <NSWindowDelegate, NSAnimationDelegate, NSCollectionViewDelegate,NSCollectionViewDataSource>
49
{
50 51 52
    BOOL videoPlaybackEnabled;
    BOOL dropzoneActive;
    BOOL minimizedView;
53
    BOOL collectionViewRemoved;
54
    NSSet<NSIndexPath *> * VLCLibraryViewItem;
55
    CGFloat lastCollectionViewHeight;
56
    NSRect frameBeforePlayback;
57 58 59 60
    NSFileManager *fileManager;
    NSString *rootPath;
    NSArray *paths ;
    VLCLibraryItem *libraryItem;
61
}
62 63
@end

64
static const float f_min_window_height = 307.;
65

66 67
@implementation VLCMainWindow

68 69 70 71 72
#pragma mark -
#pragma mark Initialization

- (void)dealloc
{
73
    [[NSNotificationCenter defaultCenter] removeObserver: self];
74 75 76 77
}

- (void)awakeFromNib
{
78 79
    [super awakeFromNib];

80 81 82 83 84 85 86 87 88 89 90
    /*
     * General setup
     */

    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [self setDelegate:self];
    [self setRestorable:NO];
    [self setExcludedFromWindowsMenu:YES];
    [self setAcceptsMouseMovedEvents:YES];
91 92
    [self setFrameAutosaveName:@"mainwindow"];

93
    _nativeFullscreenMode = var_InheritBool(getIntf(), "macosx-nativefullscreenmode");
94 95 96 97 98 99 100 101

    /*
     * Set up translatable strings for the UI elements
     */

    // Window title
    [self setTitle:_NS("VLC media player")];

102
    // Set that here as IB seems to be buggy
103
    [self setContentMinSize:NSMakeSize(604., f_min_window_height)];
104

105 106
    _fspanel = [[VLCFSPanelController alloc] init];
    [_fspanel showWindow:self];
107

108
    /* make sure we display the desired default appearance when VLC launches for the first time */
109
    if (![defaults objectForKey:@"VLCFirstRun"]) {
110 111
        [defaults setObject:[NSDate date] forKey:@"VLCFirstRun"];

112

113 114 115 116 117 118
        NSAlert *albumArtAlert = [[NSAlert alloc] init];
        [albumArtAlert setMessageText:_NS("Check for album art and metadata?")];
        [albumArtAlert setInformativeText:_NS("VLC can check online for album art and metadata to enrich your playback experience, e.g. by providing track information when playing Audio CDs. To provide this functionality, VLC will send information about your contents to trusted services in an anonymized form.")];
        [albumArtAlert addButtonWithTitle:_NS("Enable Metadata Retrieval")];
        [albumArtAlert addButtonWithTitle:_NS("No, Thanks")];

119
        NSInteger returnValue = [albumArtAlert runModal];
120
        config_PutInt("metadata-network-access", returnValue == NSAlertFirstButtonReturn);
121 122
    }

Felix Paul Kühne's avatar
Felix Paul Kühne committed
123 124 125
    [defaultCenter addObserver: self selector: @selector(someWindowWillClose:) name: NSWindowWillCloseNotification object: nil];
    [defaultCenter addObserver: self selector: @selector(someWindowWillMiniaturize:) name: NSWindowWillMiniaturizeNotification object:nil];
    [defaultCenter addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
126 127

    /* sanity check for the window size */
128
    NSRect frame = [self frame];
129 130
    NSSize screenSize = [[self screen] frame].size;
    if (screenSize.width <= frame.size.width || screenSize.height <= frame.size.height) {
131
        self.nativeVideoSize = screenSize;
132 133
        [self resizeWindow];
    }
134

135
    /* update fs button to reflect state for next startup */
136
    if (var_InheritBool(pl_Get(getIntf()), "fullscreen"))
137
        [self.controlsBar setFullscreenState:YES];
138

139
    /* Initialise collectionview  when Player loads  */
140 141
    [self makeCollectionViewVisible];
    [self.collectionView reloadData];
142

143
}
144

145

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
#pragma mark - key and event handling

- (BOOL)isEvent:(NSEvent *)o_event forKey:(const char *)keyString
{
    char *key;
    NSString *o_key;

    key = config_GetPsz(keyString);
    o_key = [NSString stringWithFormat:@"%s", key];
    FREENULL(key);

    unsigned int i_keyModifiers = [[VLCStringUtility sharedInstance] VLCModifiersToCocoa:o_key];

    NSString * characters = [o_event charactersIgnoringModifiers];
    if ([characters length] > 0) {
        return [[characters lowercaseString] isEqualToString: [[VLCStringUtility sharedInstance] VLCKeyToString: o_key]] &&
        (i_keyModifiers & NSShiftKeyMask)     == ([o_event modifierFlags] & NSShiftKeyMask) &&
        (i_keyModifiers & NSControlKeyMask)   == ([o_event modifierFlags] & NSControlKeyMask) &&
        (i_keyModifiers & NSAlternateKeyMask) == ([o_event modifierFlags] & NSAlternateKeyMask) &&
        (i_keyModifiers & NSCommandKeyMask)   == ([o_event modifierFlags] & NSCommandKeyMask);
    }
    return NO;
}

- (BOOL)performKeyEquivalent:(NSEvent *)o_event
{
    BOOL b_force = NO;
    // these are key events which should be handled by vlc core, but are attached to a main menu item
    if (![self isEvent: o_event forKey: "key-vol-up"] &&
        ![self isEvent: o_event forKey: "key-vol-down"] &&
        ![self isEvent: o_event forKey: "key-vol-mute"] &&
        ![self isEvent: o_event forKey: "key-prev"] &&
        ![self isEvent: o_event forKey: "key-next"] &&
        ![self isEvent: o_event forKey: "key-jump+short"] &&
        ![self isEvent: o_event forKey: "key-jump-short"]) {
        /* We indeed want to prioritize some Cocoa key equivalent against libvlc,
         so we perform the menu equivalent now. */
        if ([[NSApp mainMenu] performKeyEquivalent:o_event])
            return TRUE;
    }
    else
        b_force = YES;

    VLCCoreInteraction *coreInteraction = [VLCCoreInteraction sharedInstance];
    return [coreInteraction hasDefinedShortcutKey:o_event force:b_force] ||
    [coreInteraction keyEvent:o_event];
}

194 195
#pragma mark - LibraryView
#pragma mark  data view vs video output handling
196 197 198
- (void)makeCollectionViewVisible
{
    [self setContentMinSize: NSMakeSize(604., f_min_window_height)];
199

200 201 202 203 204 205 206 207 208 209 210
    NSRect old_frame = [self frame];
    CGFloat newHeight = [self minSize].height;
    if (old_frame.size.height < newHeight) {
        NSRect new_frame = old_frame;
        new_frame.origin.y = old_frame.origin.y + old_frame.size.height - newHeight;
        new_frame.size.height = newHeight;

        [[self animator] setFrame:new_frame display:YES animate:YES];
    }

    [self.videoView setHidden:YES];
211
    [self.topView setHidden:NO];
212 213 214 215 216 217 218
    [_collectionView setHidden:NO];
    if (self.nativeFullscreenMode && [self fullscreen]) {
        [self showControlsBar];
        [self.fspanel setNonActive];
    }

    [self makeFirstResponder:_collectionView];
219
    
220 221
    self.dummyData=[NSMutableArray arrayWithCapacity:0 ];
    self.collectionView.wantsLayer = YES;
222 223 224 225
    [self prepareData];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.wantsLayer = YES;
226
    [self.collectionView registerClass:[VLCLibraryView class] forItemWithIdentifier:@"dummyViews"];
227 228
    
    NSCollectionViewFlowLayout *flowLayout = [[NSCollectionViewFlowLayout alloc]  init];
229
    flowLayout.itemSize = NSMakeSize(190,241);
230 231 232 233 234 235 236
    flowLayout.sectionInset = NSEdgeInsetsMake(10, 10, 10, 10);
    flowLayout.minimumInteritemSpacing = 20.0;
    flowLayout.minimumLineSpacing = 20.0;
    self.collectionView.collectionViewLayout = flowLayout;
    [self.collectionView reloadData];
}

237 238 239 240 241 242 243
// Hides the collection view and makes the vout view in foreground
- (void)makeCollectionViewHidden
{
    [self setContentMinSize: NSMakeSize(604., f_min_video_height)];
    
    [_collectionView setHidden:YES];
    [self.videoView setHidden:NO];
244
    [self.topView setHidden:YES];
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
    if (self.nativeFullscreenMode && [self fullscreen]) {
        [self hideControlsBar];
        [self.fspanel setActive];
    }
    
    if ([[self.videoView subviews] count] > 0)
        [self makeFirstResponder: [[self.videoView subviews] firstObject]];
}

- (void)hideCollectionView:(BOOL)resize
{
    if (resize) {
        NSRect winrect = [self frame];
        lastCollectionViewHeight = [_collectionView frame].size.height;
        winrect.size.height = winrect.size.height - lastCollectionViewHeight;
        winrect.origin.y = winrect.origin.y + lastCollectionViewHeight;
        [self setFrame:winrect display:YES animate:YES];
    }
    
    [self setContentMinSize: NSMakeSize(604., [self.controlsBar height])];
    [self setContentMaxSize: NSMakeSize(FLT_MAX, [self.controlsBar height])];
    
    collectionViewRemoved = YES;
268

269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
}

- (void)showCollectionView:(BOOL)resize
{
    [self updateWindow];
    [self setContentMinSize:NSMakeSize(604., f_min_window_height)];
    [self setContentMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)];
    
    if (resize) {
        NSRect winrect;
        winrect = [self frame];
        winrect.size.height = winrect.size.height + lastCollectionViewHeight;
        winrect.origin.y = winrect.origin.y - lastCollectionViewHeight;
        [self setFrame:winrect display:YES animate:YES];
    }
    
    collectionViewRemoved = NO;
}

#pragma mark  Generating dummyData for the libraryView
/*
 Assigning values from local source to the dataModel
 */

293
- (void)prepareData {
294 295 296 297
     fileManager = [NSFileManager defaultManager];
     rootPath = @"/Users/vibhoothiiaanand/Desktop/dummyVideos";
     NSError *error = nil;
     paths = [fileManager contentsOfDirectoryAtPath:rootPath error:&error];
298
    for(NSString *path in paths){
299 300 301
         NSString *videoPath = [rootPath stringByAppendingFormat:@"/%@",path];
        NSLog(@"Video Path:%@",videoPath);
        NSURL *url = [NSURL fileURLWithPath:videoPath];
302 303
    AVAsset *asset = [AVAsset assetWithURL:url];
    AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
304
    imageGenerator.appliesPreferredTrackTransform=YES;
305 306 307 308 309 310
    CMTime time = [asset duration];
    time.value = 0;
    float duration = CMTimeGetSeconds([asset duration]);
        CGImageRef imgRef = [imageGenerator copyCGImageAtTime:CMTimeMake(10, duration) actualTime:NULL error:nil];
        NSImage *thumbinail =[[NSImage alloc] initWithCGImage:imgRef size:NSSizeFromCGSize(CGSizeMake(100.0, 100.0))];
        if(thumbinail){
311
            self.dataModel = [[VLCLibraryItem alloc] init ] ;
312 313 314
            self.dataModel.thumbnail = thumbinail;
            self.dataModel.videoTitle= path;
            self.dataModel.year = @"2012";
315
            self.dataModel.length = @"40.4 MB";
316
            self.dataModel.videoURL=[url absoluteString];
317
            [self.dummyData addObject:self.dataModel] ;
318
        }
319
  
320
    }
321
      NSLog(@"DataModel dummy %@",self.dummyData);
322 323
}

324
#pragma mark  libraryView generation using modern APIs
325 326 327 328 329 330 331 332

- (NSSet<NSIndexPath *> *)collectionView:(NSCollectionView *)collectionView shouldChangeItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths toHighlightState:(NSCollectionViewItemHighlightState)highlightState {
    return indexPaths;
}

- (void)collectionView:(NSCollectionView *)collectionView didSelectItemsAtIndexPaths:VLCLibraryViewItem
{
    NSLog(@"Video at:%@ is Selected",VLCLibraryViewItem);
333
    
334 335 336 337 338 339 340 341
    NSString *videoURL;
    VLCLibraryItem *video = [self.dummyData objectAtIndex:collectionView.selectionIndexes.firstIndex];
    videoURL = video.videoURL;
    NSLog(@"VideoURL:%@ ",videoURL);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:videoURL forKey:@"ITEM_URL"];
    NSArray *videoPlayback = [NSArray arrayWithObject:dic];
    [[[VLCMain sharedInstance] playlist] addPlaylistItems:videoPlayback];
    
342
}
343
     
344
- (NSInteger)collectionView:(NSCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
345 346
    
    return self.dummyData.count;
347
}
348 349
- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
{
350
    /*
351 352
     Pass the metadata to the DataModel for assinging values to the views
     and return updated view
353
     */
354
    VLCLibraryView *item = [collectionView makeItemWithIdentifier:@"dummyViews" forIndexPath:indexPath];
355
    libraryItem = [self.dummyData objectAtIndex:indexPath.item];
356
    [item assignValueForDataModel:libraryItem];
357
    return item;
358 359 360 361
}

- (NSInteger)numberOfSectionsInCollectionView:(NSCollectionView *)collectionView {
    return 1;
362 363
}

Vibhoothi's avatar
Vibhoothi committed
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
#pragma mark - Play Queue
#pragma mark  popOver Initialisation

- (BOOL)buttonIsPressed
{
    return self.playQueueButton.intValue == 1;
}

- (IBAction)popOver:(id)sender {
    NSLog(@"VLC: play-Queue tapped");
    if (self.buttonIsPressed)
    {
        [self.playQueuePopOver showRelativeToRect:[self.playQueueButton bounds] ofView:self.playQueueButton preferredEdge:NSMaxYEdge];
    } else {
        [self.playQueuePopOver close];
    }
}




385 386
#pragma mark -
#pragma mark  Playlist State toggle
387
- (void)changePlaylistState:(VLCPlaylistStateEvent)event
388
{
389 390
    // Beware, this code is really ugly

391
    msg_Dbg(getIntf(), "toggle playlist from state: removed collectionview %i, minimized view %i. Event %i", collectionViewRemoved, minimizedView, event);
392 393
    if (![self isVisible] && event == psUserMenuEvent) {
        [self makeKeyAndOrderFront: nil];
394
        return;
395 396
    }

397 398
    BOOL activeVideo = [[VLCMain sharedInstance] activeVideoPlayback];
    BOOL restored = NO;
399

400
    // ignore alt if triggered through main menu shortcut
401
    BOOL b_have_alt_key = ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0;
402
    if (event == psUserMenuEvent)
403 404
        b_have_alt_key = NO;

405 406 407 408
    // eUserMenuEvent is now handled same as eUserEvent
    if(event == psUserMenuEvent)
        event = psUserEvent;

409 410 411 412
    if (!(self.nativeFullscreenMode && self.fullscreen) && !collectionViewRemoved && ((b_have_alt_key && activeVideo)
                                                                                    || (self.nonembedded && event == psUserEvent)
                                                                                    || (!activeVideo && event == psUserEvent)
                                                                                    || (minimizedView && event == psVideoStartedOrStoppedEvent))) {
413 414
        // for starting playback, window is resized through resized events
        // for stopping playback, resize through reset to previous frame
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
        [self hideCollectionView: event != psVideoStartedOrStoppedEvent];
        minimizedView = NO;
    } else {
        if (collectionViewRemoved) {
            if (!self.nonembedded || (event == psUserEvent && self.nonembedded))
                [self showCollectionView: event != psVideoStartedOrStoppedEvent];

            if (event != psUserEvent)
                minimizedView = YES;
            else
                minimizedView = NO;

            if (activeVideo)
                restored = YES;
        }

        if (!self.nonembedded) {
            if (([self.videoView isHidden] && activeVideo) || restored || (activeVideo && event != psUserEvent))
                [self makeCollectionViewHidden];
            else
                [self makeCollectionViewVisible];
        } else {
437
            [self.collectionView setHidden: NO];
438
            [self.videoView setHidden: YES];
439
            [self.topView setHidden:YES];
440 441 442 443 444 445 446
            [self showControlsBar];
        }
    }

    msg_Dbg(getIntf(), "toggle playlist to state: removed collectionview %i, minimized view %i", collectionViewRemoved, minimizedView);
}

447
#pragma mark -
448
#pragma mark overwritten default window functionality
449

450 451
- (void)windowResizedOrMoved:(NSNotification *)notification
{
452
    [self saveFrameUsingName:[self frameAutosaveName]];
453 454
}

455 456
- (void)applicationWillTerminate:(NSNotification *)notification
{
457
    [self saveFrameUsingName:[self frameAutosaveName]];
458 459
}

460

461 462
- (void)someWindowWillClose:(NSNotification *)notification
{
463
    id obj = [notification object];
464

465 466
    // hasActiveVideo is defined for VLCVideoWindowCommon and subclasses
    if ([obj respondsToSelector:@selector(hasActiveVideo)] && [obj hasActiveVideo]) {
467 468 469
        if ([[VLCMain sharedInstance] activeVideoPlayback])
            [[VLCCoreInteraction sharedInstance] stop];
    }
470 471 472 473
}

- (void)someWindowWillMiniaturize:(NSNotification *)notification
{
474
    if (config_GetInt("macosx-pause-minimized")) {
475
        id obj = [notification object];
476

477
        if ([obj class] == [VLCVideoWindowCommon class] || [obj class] == [VLCDetachedVideoWindow class] || ([obj class] == [VLCMainWindow class] && !self.nonembedded)) {
478
            if ([[VLCMain sharedInstance] activeVideoPlayback])
479 480
                [[VLCCoreInteraction sharedInstance] pause];
        }
481 482 483
    }
}

484 485
#pragma mark -
#pragma mark Update interface and respond to foreign events
486

487 488
- (void)updateTimeSlider
{
489 490
    [self.controlsBar updateTimeSlider];
    [self.fspanel updatePositionAndTime];
491

492
    [[[VLCMain sharedInstance] voutProvider] updateControlsBarsUsingBlock:^(VLCControlsBarCommon *controlsBar) {
493 494
        [controlsBar updateTimeSlider];
    }];
495 496

    [[VLCCoreInteraction sharedInstance] updateAtoB];
497 498
}

499
- (void)updateName
500
{
501
    input_thread_t *p_input;
502
    p_input = pl_CurrentInput(getIntf());
503
    if (p_input) {
504
        NSString *aString = @"";
505

506
        if (!config_GetPsz("video-title")) {
507
            char *format = var_InheritString(getIntf(), "input-title-format");
508
            if (format) {
509
                char *formated = vlc_strfinput(p_input, format);
510 511 512 513
                free(format);
                aString = toNSStr(formated);
                free(formated);
            }
514
        } else
515
            aString = toNSStr(config_GetPsz("video-title"));
516

517
        char *uri = input_item_GetURI(input_GetItem(p_input));
518

519
        NSURL * o_url = [NSURL URLWithString:toNSStr(uri)];
520
        if ([o_url isFileURL]) {
521
            [self setRepresentedURL: o_url];
522
            [[[VLCMain sharedInstance] voutProvider] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
523 524
                [o_window setRepresentedURL:o_url];
            }];
525
        } else {
526
            [self setRepresentedURL: nil];
527
            [[[VLCMain sharedInstance] voutProvider] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
528 529
                [o_window setRepresentedURL:nil];
            }];
530
        }
531
        free(uri);
532

533
        if ([aString isEqualToString:@""]) {
534 535 536 537
            if ([o_url isFileURL])
                aString = [[NSFileManager defaultManager] displayNameAtPath: [o_url path]];
            else
                aString = [o_url absoluteString];
538
        }
539

540 541
        if ([aString length] > 0) {
            [self setTitle: aString];
542
            [[[VLCMain sharedInstance] voutProvider] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
543 544 545
                [o_window setTitle:aString];
            }];

546
            [self.fspanel setStreamTitle: aString];
547
        } else {
548
            [self setTitle: _NS("VLC media player")];
549 550
            [self setRepresentedURL: nil];
        }
551

552 553
        vlc_object_release(p_input);
    } else {
554
        [self setTitle: _NS("VLC media player")];
555
        [self setRepresentedURL: nil];
556
    }
557 558
}

559 560
- (void)updateWindow
{
561
    [self.controlsBar updateControls];
562
    [[[VLCMain sharedInstance] voutProvider] updateControlsBarsUsingBlock:^(VLCControlsBarCommon *controlsBar) {
563 564
        [controlsBar updateControls];
    }];
565

566 567
    bool b_seekable = false;

568
    playlist_t *p_playlist = pl_Get(getIntf());
569
    input_thread_t *p_input = playlist_CurrentInput(p_playlist);
570
    if (p_input) {
571
        /* seekable streams */
572
        b_seekable = var_GetBool(p_input, "can-seek");
573

574
        vlc_object_release(p_input);
575 576
    }

577
    [self updateTimeSlider];
578 579
    if ([self.fspanel respondsToSelector:@selector(setSeekable:)])
        [self.fspanel setSeekable: b_seekable];
580 581 582 583
}

- (void)setPause
{
584 585
    [self.controlsBar setPause];
    [self.fspanel setPause];
586

587
    [[[VLCMain sharedInstance] voutProvider] updateControlsBarsUsingBlock:^(VLCControlsBarCommon *controlsBar) {
588 589
        [controlsBar setPause];
    }];
590 591 592 593
}

- (void)setPlay
{
594 595
    [self.controlsBar setPlay];
    [self.fspanel setPlay];
596

597
    [[[VLCMain sharedInstance] voutProvider] updateControlsBarsUsingBlock:^(VLCControlsBarCommon *controlsBar) {
598 599
        [controlsBar setPlay];
    }];
600 601
}

602
- (void)updateVolumeSlider
603
{
604
    [(VLCMainWindowControlsBar *)[self controlsBar] updateVolumeSlider];
605
    [self.fspanel setVolumeLevel:[[VLCCoreInteraction sharedInstance] volume]];
606 607
}

608 609
#pragma mark -
#pragma mark Video Output handling
610

611 612
- (void)videoplayWillBeStarted
{
613
    if (!self.fullscreen)
614 615 616
        frameBeforePlayback = [self frame];
}

617
- (void)setVideoplayEnabled
618
{
619
    BOOL b_videoPlayback = [[VLCMain sharedInstance] activeVideoPlayback];
620

621
    if (!b_videoPlayback) {
622
        if (!self.nonembedded && (!self.nativeFullscreenMode || (self.nativeFullscreenMode && !self.fullscreen)) && frameBeforePlayback.size.width > 0 && frameBeforePlayback.size.height > 0) {
623 624

            // only resize back to minimum view of this is still desired final state
625
            CGFloat f_threshold_height = f_min_video_height + [self.controlsBar height];
626
            if(frameBeforePlayback.size.height > f_threshold_height || minimizedView) {
627 628 629 630 631 632

                if ([[VLCMain sharedInstance] isTerminating])
                    [self setFrame:frameBeforePlayback display:YES];
                else
                    [[self animator] setFrame:frameBeforePlayback display:YES];

633
            }
634 635 636
        }

        frameBeforePlayback = NSMakeRect(0, 0, 0, 0);
637

638
        // update fs button to reflect state for next startup
639
        if (var_InheritBool(getIntf(), "fullscreen") || var_GetBool(pl_Get(getIntf()), "fullscreen")) {
640
            [self.controlsBar setFullscreenState:YES];
641 642
        }

643
        [[[VLCMain sharedInstance] voutProvider] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
644

645 646 647
        // restore alpha value to 1 for the case that macosx-opaqueness is set to < 1
        [self setAlphaValue:1.0];
    }
648

649
    if (self.nativeFullscreenMode) {
650 651
        if ([self hasActiveVideo] && [self fullscreen] && b_videoPlayback) {
            [self hideControlsBar];
652
            [self.fspanel setActive];
653
        } else {
654
            [self showControlsBar];
655
            [self.fspanel setNonActive];
656
        }
657
    }
658
}
659

660 661
#pragma mark -
#pragma mark Fullscreen support
662

663 664
- (void)showFullscreenController
{
665 666
    id currentWindow = [NSApp keyWindow];
    if ([currentWindow respondsToSelector:@selector(hasActiveVideo)] && [currentWindow hasActiveVideo]) {
667
        if ([currentWindow respondsToSelector:@selector(fullscreen)] && [currentWindow fullscreen] && ![[currentWindow videoView] isHidden]) {
668 669

            if ([[VLCMain sharedInstance] activeVideoPlayback])
670
                [self.fspanel fadeIn];
671 672
        }
    }
673

674 675
}

676
@end
677

678 679 680
@interface VLCDetachedVideoWindow ()
@end

681 682
@implementation VLCDetachedVideoWindow

683 684
- (void)awakeFromNib
{
685 686
    // sets lion fullscreen behaviour
    [super awakeFromNib];
687 688
    [self setAcceptsMouseMovedEvents: YES];

689
    [self setContentMinSize: NSMakeSize(363., f_min_video_height + [[self controlsBar] height])];
690 691
}

692
@end