Skip to content

Commit 12046f9

Browse files
committed
Playback with buttons
1 parent 856ea31 commit 12046f9

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

TestSwift/Base.lproj/Main.storyboard

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,6 @@
117117
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="q8P-5k-V04" id="Hvr-uO-kzf">
118118
<autoresizingMask key="autoresizingMask"/>
119119
<subviews>
120-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dE4-MC-wkr">
121-
<rect key="frame" x="-23" y="-15" width="46" height="30"/>
122-
<state key="normal" title="▶️">
123-
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
124-
</state>
125-
<variation key="heightClass=regular-widthClass=compact" fixedFrame="YES">
126-
<rect key="frame" x="20" y="7" width="30" height="30"/>
127-
</variation>
128-
</button>
129120
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" tag="1" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.25" translatesAutoresizingMaskIntoConstraints="NO" id="DPO-xR-L6h">
130121
<rect key="frame" x="0.0" y="-21" width="42" height="21"/>
131122
<fontDescription key="fontDescription" name="HelveticaNeue-Thin" family="Helvetica Neue" pointSize="18"/>
@@ -135,22 +126,31 @@
135126
<rect key="frame" x="58" y="7" width="208" height="33"/>
136127
</variation>
137128
</label>
129+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="▶️" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Pka-3e-WDz">
130+
<rect key="frame" x="0.0" y="-21" width="42" height="21"/>
131+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
132+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
133+
<nil key="highlightedColor"/>
134+
<variation key="heightClass=regular-widthClass=compact" fixedFrame="YES">
135+
<rect key="frame" x="20" y="13" width="23" height="21"/>
136+
</variation>
137+
</label>
138138
</subviews>
139139
<variation key="default">
140140
<mask key="subviews">
141-
<exclude reference="dE4-MC-wkr"/>
142141
<exclude reference="DPO-xR-L6h"/>
142+
<exclude reference="Pka-3e-WDz"/>
143143
</mask>
144144
</variation>
145145
<variation key="heightClass=regular-widthClass=compact">
146146
<mask key="subviews">
147-
<include reference="dE4-MC-wkr"/>
148147
<include reference="DPO-xR-L6h"/>
148+
<include reference="Pka-3e-WDz"/>
149149
</mask>
150150
</variation>
151151
</tableViewCellContentView>
152152
<connections>
153-
<outlet property="playButton" destination="dE4-MC-wkr" id="h6A-4C-eZj"/>
153+
<outlet property="playIcon" destination="Pka-3e-WDz" id="yhy-MQ-oh1"/>
154154
<outlet property="titleLabel" destination="DPO-xR-L6h" id="Zqj-m2-6gK"/>
155155
</connections>
156156
</tableViewCell>

TestSwift/Classes/DetailsViewController.swift

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class DetailsViewController: UIViewController, UITableViewDelegate, UITableViewD
1717
var album: Album?
1818
var tracks: Track[] = []
1919
var api: APIController?
20+
var mediaPlayer: MPMoviePlayerController = MPMoviePlayerController()
2021

2122
init(coder aDecoder: NSCoder!) {
2223
super.init(coder: aDecoder)
@@ -36,7 +37,6 @@ class DetailsViewController: UIViewController, UITableViewDelegate, UITableViewD
3637
}
3738

3839
func didRecieveAPIResults(results: NSDictionary) {
39-
println("Got track deets \(results)")
4040
if let allResults = results["results"] as? NSDictionary[] {
4141
for trackInfo in allResults {
4242
// Create the track
@@ -51,6 +51,25 @@ class DetailsViewController: UIViewController, UITableViewDelegate, UITableViewD
5151
tracksTableView.reloadData()
5252
}
5353

54+
func tableView(tableView: UITableView!, didDeselectRowAtIndexPath indexPath: NSIndexPath!) {
55+
if let cell = tableView.cellForRowAtIndexPath(indexPath) as? TrackCell {
56+
cell.playIcon.text = "▶️"
57+
}
58+
}
59+
60+
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
61+
var track = tracks[indexPath.row]
62+
63+
mediaPlayer.stop()
64+
mediaPlayer.contentURL = NSURL(string: track.previewUrl)
65+
mediaPlayer.play()
66+
67+
if let cell = tableView.cellForRowAtIndexPath(indexPath) as? TrackCell {
68+
cell.playIcon.text = "⬛️"
69+
}
70+
71+
}
72+
5473

5574
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
5675
return tracks.count
@@ -61,14 +80,7 @@ class DetailsViewController: UIViewController, UITableViewDelegate, UITableViewD
6180

6281
var track = tracks[indexPath.row]
6382
cell.titleLabel.text = track.title
64-
65-
/*var playButton = cell.viewWithTag(0) as UIButton
66-
var titleText = cell.viewWithTag(1) as UILabel
67-
68-
var track = tracks[indexPath.row]
69-
70-
titleText.text = track.title
71-
*/
83+
cell.playIcon.text = "▶️"
7284

7385
return cell
7486
}

TestSwift/TrackCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111

1212
class TrackCell: UITableViewCell {
1313

14-
@IBOutlet var playButton: UIButton
14+
@IBOutlet var playIcon: UILabel
1515
@IBOutlet var titleLabel: UILabel
1616

1717
}

0 commit comments

Comments
 (0)