Commit c6208dff authored by Felix Paul Kühne's avatar Felix Paul Kühne

add basic mini playback view

parent 03283d86
/*****************************************************************************
* VLCMiniPlaybackView.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Author: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCFrostedGlasView.h"
@interface VLCMiniPlaybackView : VLCFrostedGlasView
- (void)setupForWork;
@end
/*****************************************************************************
* VLCMiniPlaybackView.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Author: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCMiniPlaybackView.h"
#import "VLCPlaybackController.h"
#import "VLCAppDelegate.h"
#import "VLCPlaylistViewController.h"
@interface VLCMiniPlaybackView () <VLCPlaybackControllerDelegate>
{
UIImageView *_artworkView;
UIView *_videoView;
UIButton *_previousButton;
UIButton *_playPauseButton;
UIButton *_nextButton;
UIButton *_expandButton;
UILabel *_metaDataLabel;
}
@end
@implementation VLCMiniPlaybackView
- (instancetype)initWithFrame:(CGRect)viewFrame
{
self = [super initWithFrame:viewFrame];
if (!self)
return self;
CGRect workingRect;
CGRect previousRect;
CGFloat buttonGap = 10.;
_artworkView = [[UIImageView alloc] initWithFrame:CGRectMake(0., 0., 60., 60.)];
_artworkView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
[self addSubview:_artworkView];
/* build buttons from right to left */
_expandButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_expandButton setImage:[UIImage imageNamed:@"ratioIcon"] forState:UIControlStateNormal];
[_expandButton sizeToFit];
_expandButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[_expandButton addTarget:self action:@selector(pushFullPlaybackView:) forControlEvents:UIControlEventTouchUpInside];
workingRect = _expandButton.frame;
workingRect.origin.x = viewFrame.size.width - buttonGap * 2. - workingRect.size.width;
workingRect.origin.y = (viewFrame.size.height - workingRect.size.height) / 2.;
_expandButton.frame = previousRect = workingRect;
[self addSubview:_expandButton];
_nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_nextButton setImage:[UIImage imageNamed:@"forwardIcon"] forState:UIControlStateNormal];
[_nextButton sizeToFit];
_nextButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[_nextButton addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
workingRect = _nextButton.frame;
workingRect.origin.x = previousRect.origin.x - buttonGap * 2. - workingRect.size.width;
workingRect.origin.y = (viewFrame.size.height - workingRect.size.height) / 2.;
_nextButton.frame = previousRect = workingRect;
[self addSubview:_nextButton];
_playPauseButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_playPauseButton setImage:[UIImage imageNamed:@"playIcon"] forState:UIControlStateNormal];
[_playPauseButton sizeToFit];
_playPauseButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[_playPauseButton addTarget:self action:@selector(playPauseAction:) forControlEvents:UIControlEventTouchUpInside];
workingRect = _playPauseButton.frame;
workingRect.origin.x = previousRect.origin.x - buttonGap - workingRect.size.width;
workingRect.origin.y = (viewFrame.size.height - workingRect.size.height) / 2.;
_playPauseButton.frame = previousRect = workingRect;
[self addSubview:_playPauseButton];
_previousButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_previousButton setImage:[UIImage imageNamed:@"backIcon"] forState:UIControlStateNormal];
[_previousButton sizeToFit];
_previousButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[_playPauseButton addTarget:self action:@selector(previousAction:) forControlEvents:UIControlEventTouchUpInside];
workingRect = _previousButton.frame;
workingRect.origin.x = previousRect.origin.x - buttonGap - workingRect.size.width;
workingRect.origin.y = (viewFrame.size.height - workingRect.size.height) / 2.;
_previousButton.frame = previousRect = workingRect;
[self addSubview:_previousButton];
CGFloat artworkViewWidth = _artworkView.frame.size.width;
_metaDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(artworkViewWidth + buttonGap, 0., previousRect.origin.x - artworkViewWidth - buttonGap, viewFrame.size.height)];
_metaDataLabel.font = [UIFont systemFontOfSize:12.];
_metaDataLabel.textColor = [UIColor VLCLightTextColor];
_metaDataLabel.numberOfLines = 0;
[self addSubview:_metaDataLabel];
return self;
}
- (void)previousAction:(id)sender
{
[[VLCPlaybackController sharedInstance] backward];
}
- (void)playPauseAction:(id)sender
{
[[VLCPlaybackController sharedInstance] playPause];
}
- (void)nextAction:(id)sender
{
[[VLCPlaybackController sharedInstance] forward];
}
- (void)pushFullPlaybackView:(id)sender
{
[VLCPlaybackController sharedInstance].videoOutputView = nil;
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate presentMovieViewController];
}
- (void)setupForWork
{
VLCPlaybackController *playbackController = [VLCPlaybackController sharedInstance];
if (playbackController.isPlaying)
[_playPauseButton setImage:[UIImage imageNamed:@"pauseIcon"] forState:UIControlStateNormal];
else
[_playPauseButton setImage:[UIImage imageNamed:@"playIcon"] forState:UIControlStateNormal];
playbackController.delegate = self;
[playbackController recoverDisplayedMetadata];
}
- (void)mediaPlayerStateChanged:(VLCMediaPlayerState)currentState
isPlaying:(BOOL)isPlaying
currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
currentMediaHasChapters:(BOOL)currentMediaHasChapters
forPlaybackController:(VLCPlaybackController *)controller
{
UIImage *playPauseImage = isPlaying ? [UIImage imageNamed:@"pauseIcon"] : [UIImage imageNamed:@"playIcon"];
[_playPauseButton setImage:playPauseImage forState:UIControlStateNormal];
}
- (void)displayMetadataForPlaybackController:(VLCPlaybackController *)controller
title:(NSString *)title
artwork:(UIImage *)artwork
artist:(NSString *)artist
album:(NSString *)album
audioOnly:(BOOL)audioOnly
{
if (audioOnly) {
_artworkView.image = artwork;
if (_videoView) {
[_videoView removeFromSuperview];
_videoView = nil;
}
} else {
_videoView = [[UIView alloc] initWithFrame:_artworkView.frame];
[self addSubview:_videoView];
controller.videoOutputView = _videoView;
}
NSString *metaDataString;
if (artist)
metaDataString = artist;
if (album)
metaDataString = [metaDataString stringByAppendingFormat:@" — %@", album];
if (metaDataString)
metaDataString = [metaDataString stringByAppendingFormat:@"\n%@", title];
else
metaDataString = title;
_metaDataLabel.text = metaDataString;
}
- (void)presentingViewControllerShouldBeClosed:(VLCPlaybackController *)controller
{
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.playlistViewController displayMiniPlaybackViewIfNeeded];
}
- (void)presentingViewControllerShouldBeClosedAfterADelay:(VLCPlaybackController *)controller
{
[self presentingViewControllerShouldBeClosed:controller];
}
@end
......@@ -337,6 +337,7 @@
7D94FCDF16DE7D1000F2623B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D94FCDE16DE7D1000F2623B /* UIKit.framework */; };
7D94FCE116DE7D1000F2623B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D94FCE016DE7D1000F2623B /* Foundation.framework */; };
7D94FCE316DE7D1000F2623B /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D94FCE216DE7D1000F2623B /* CoreGraphics.framework */; };
7D95610B1AF3E9E800779745 /* VLCMiniPlaybackView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D95610A1AF3E9E800779745 /* VLCMiniPlaybackView.m */; };
7D9870201A3DEC99009CF27D /* modernSliderKnob@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D98701F1A3DEC99009CF27D /* modernSliderKnob@3x.png */; };
7D9870221A3DECA8009CF27D /* forwardIcon@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D9870211A3DECA8009CF27D /* forwardIcon@3x.png */; };
7D9870241A3DECB1009CF27D /* arrows@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D9870231A3DECB1009CF27D /* arrows@3x.png */; };
......@@ -1250,6 +1251,8 @@
7D94FCDE16DE7D1000F2623B /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
7D94FCE016DE7D1000F2623B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
7D94FCE216DE7D1000F2623B /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
7D9561091AF3E9E800779745 /* VLCMiniPlaybackView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCMiniPlaybackView.h; path = Sources/VLCMiniPlaybackView.h; sourceTree = SOURCE_ROOT; };
7D95610A1AF3E9E800779745 /* VLCMiniPlaybackView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCMiniPlaybackView.m; path = Sources/VLCMiniPlaybackView.m; sourceTree = SOURCE_ROOT; };
7D98701F1A3DEC99009CF27D /* modernSliderKnob@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "modernSliderKnob@3x.png"; sourceTree = "<group>"; };
7D9870211A3DECA8009CF27D /* forwardIcon@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "forwardIcon@3x.png"; sourceTree = "<group>"; };
7D9870231A3DECB1009CF27D /* arrows@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "arrows@3x.png"; sourceTree = "<group>"; };
......@@ -2291,6 +2294,8 @@
7DE56C191AD93F9100E8CA00 /* VLCPlaybackController.m */,
7D37848D183A98B6009EE944 /* VLCMovieViewController.h */,
7D37848E183A98B6009EE944 /* VLCMovieViewController.m */,
7D9561091AF3E9E800779745 /* VLCMiniPlaybackView.h */,
7D95610A1AF3E9E800779745 /* VLCMiniPlaybackView.m */,
7D378490183A98BF009EE944 /* VLCExternalDisplayController.h */,
7D378491183A98BF009EE944 /* VLCExternalDisplayController.m */,
7D4625861A5614A1001A80B4 /* VLCEqualizerView.h */,
......@@ -3690,6 +3695,7 @@
2915542617490A9C00B86CAD /* DDFileLogger.m in Sources */,
26D4AF8D1A78379000D5EC65 /* VLCSharedLibraryListViewController.m in Sources */,
2915542717490A9C00B86CAD /* DDLog.m in Sources */,
7D95610B1AF3E9E800779745 /* VLCMiniPlaybackView.m in Sources */,
2915542817490A9C00B86CAD /* DDTTYLogger.m in Sources */,
2915542917490A9C00B86CAD /* ContextFilterLogFormatter.m in Sources */,
2915542A17490A9C00B86CAD /* DispatchQueueLogFormatter.m in Sources */,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment