Skip to content
This repository has been archived by the owner on Jun 21, 2020. It is now read-only.

Commit

Permalink
[global] open the playing app on tapping the artwork
Browse files Browse the repository at this point in the history
  • Loading branch information
kirb committed Jul 6, 2017
1 parent 89e5067 commit 4cb763d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
26 changes: 1 addition & 25 deletions global/BridgingHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,5 @@
#import <MediaPlayerUI/MPUNowPlayingMetadata.h>
#import <MediaPlayerUI/MPUTransportControlsView.h>
#import <MediaRemote/MediaRemote.h>
#import <MobileCoreServices/LSApplicationProxy.h>
#import <MobileCoreServices/LSApplicationWorkspace.h>
#import <UIKit/UIColor+Private.h>

typedef NS_ENUM(NSInteger, MPUNowPlayingTitlesViewStyle) {
MPUNowPlayingTitlesViewStyleIdk
};

@interface MPUNowPlayingTitlesView : UIView

- (instancetype)initWithStyle:(MPUNowPlayingTitlesViewStyle)style;

@property (nonatomic) MPUNowPlayingTitlesViewStyle style;

@property (nonatomic, copy) NSString *titleText;
@property (nonatomic, copy) NSString *albumText;
@property (nonatomic, copy) NSString *artistText;
@property (nonatomic, copy) NSString *stationNameText;

@property (nonatomic, retain) NSDictionary *titleTextAttributes;
@property (nonatomic, retain) NSDictionary *detailTextAttributes;

@property (getter=isExplicit, nonatomic) BOOL explicit;

@property (getter=isMarqueeEnabled, nonatomic) BOOL marqueeEnabled;

@end
18 changes: 17 additions & 1 deletion global/MediaControlsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ class MediaControlsViewController: UIViewController, MPUNowPlayingDelegate {

view.autoresizingMask = [ .flexibleWidth ]


// construct the views
containerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(containerView)

artworkView.translatesAutoresizingMaskIntoConstraints = false
artworkView.activated = true
artworkView.addTarget(self, action: #selector(self.artworkTapped), for: .touchUpInside)
containerView.addSubview(artworkView)

labelsContainerView.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -202,6 +202,10 @@ class MediaControlsViewController: UIViewController, MPUNowPlayingDelegate {
return
}

// for some reason, this starts off being nil and calling it causes it to be populated, which
// we'll need to open the app if the artwork view is tapped
_ = nowPlayingController.nowPlayingAppDisplayID

// set the labels to something useful
let attributes = [
NSFontAttributeName: UIFont.preferredFont(forTextStyle: .body),
Expand Down Expand Up @@ -236,5 +240,17 @@ class MediaControlsViewController: UIViewController, MPUNowPlayingDelegate {
func nowPlayingController(_ nowPlayingController: MPUNowPlayingController!, playbackStateDidChange state: Bool) {
artworkView.setActivated(state, animated: true)
}

// MARK: - Callbacks

func artworkTapped() {
guard let bundleID = nowPlayingController.nowPlayingAppDisplayID else {
// nothing playing, probably. nothing to do here
return
}

// launch the app, hopefully
LSApplicationWorkspace.default().openApplication(withBundleID: bundleID)
}

}

0 comments on commit 4cb763d

Please sign in to comment.