Skip to content

Commit cad2a2b

Browse files
committed
YouTube Helper Library
1 parent d581074 commit cad2a2b

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

live-event-app/live-event-app.xcodeproj/project.pbxproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
3DE7581D292B88020083EAB0 /* PubNubChat in Frameworks */ = {isa = PBXBuildFile; productRef = 3DE7581C292B88020083EAB0 /* PubNubChat */; };
4040
3DE7581F292B88020083EAB0 /* PubNubChatComponents in Frameworks */ = {isa = PBXBuildFile; productRef = 3DE7581E292B88020083EAB0 /* PubNubChatComponents */; };
4141
3DE75827292F723C0083EAB0 /* LiveEventAppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DE75826292F723C0083EAB0 /* LiveEventAppUITests.swift */; };
42+
3DED7690295DA16B0048E272 /* YouTubeiOSPlayerHelper in Frameworks */ = {isa = PBXBuildFile; productRef = 3DED768F295DA16B0048E272 /* YouTubeiOSPlayerHelper */; };
4243
3DFB1F9F2934B87500DDF361 /* TimeLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DFB1F952934B87500DDF361 /* TimeLogger.swift */; };
4344
3DFB1FA02934B87500DDF361 /* DebugViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DFB1F962934B87500DDF361 /* DebugViewController.swift */; };
4445
3DFB1FA12934B87500DDF361 /* UIView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DFB1F982934B87500DDF361 /* UIView+Extensions.swift */; };
@@ -110,6 +111,7 @@
110111
files = (
111112
3DE7581F292B88020083EAB0 /* PubNubChatComponents in Frameworks */,
112113
3DE7581D292B88020083EAB0 /* PubNubChat in Frameworks */,
114+
3DED7690295DA16B0048E272 /* YouTubeiOSPlayerHelper in Frameworks */,
113115
);
114116
runOnlyForDeploymentPostprocessing = 0;
115117
};
@@ -277,6 +279,7 @@
277279
packageProductDependencies = (
278280
3DE7581C292B88020083EAB0 /* PubNubChat */,
279281
3DE7581E292B88020083EAB0 /* PubNubChatComponents */,
282+
3DED768F295DA16B0048E272 /* YouTubeiOSPlayerHelper */,
280283
);
281284
productName = "live-event-app";
282285
productReference = 3DE75804292B876C0083EAB0 /* live-event-app.app */;
@@ -330,6 +333,7 @@
330333
mainGroup = 3DE757FB292B876C0083EAB0;
331334
packageReferences = (
332335
3DE7581B292B88020083EAB0 /* XCRemoteSwiftPackageReference "chat-components-ios" */,
336+
3DED768E295DA16B0048E272 /* XCRemoteSwiftPackageReference "youtube-ios-player-helper" */,
333337
);
334338
productRefGroup = 3DE75805292B876C0083EAB0 /* Products */;
335339
projectDirPath = "";
@@ -686,6 +690,14 @@
686690
version = 0.2.0;
687691
};
688692
};
693+
3DED768E295DA16B0048E272 /* XCRemoteSwiftPackageReference "youtube-ios-player-helper" */ = {
694+
isa = XCRemoteSwiftPackageReference;
695+
repositoryURL = "https://github.com/youtube/youtube-ios-player-helper";
696+
requirement = {
697+
kind = upToNextMajorVersion;
698+
minimumVersion = 1.0.0;
699+
};
700+
};
689701
/* End XCRemoteSwiftPackageReference section */
690702

691703
/* Begin XCSwiftPackageProductDependency section */
@@ -699,6 +711,11 @@
699711
package = 3DE7581B292B88020083EAB0 /* XCRemoteSwiftPackageReference "chat-components-ios" */;
700712
productName = PubNubChatComponents;
701713
};
714+
3DED768F295DA16B0048E272 /* YouTubeiOSPlayerHelper */ = {
715+
isa = XCSwiftPackageProductDependency;
716+
package = 3DED768E295DA16B0048E272 /* XCRemoteSwiftPackageReference "youtube-ios-player-helper" */;
717+
productName = YouTubeiOSPlayerHelper;
718+
};
702719
/* End XCSwiftPackageProductDependency section */
703720
};
704721
rootObject = 3DE757FC292B876C0083EAB0 /* Project object */;

live-event-app/live-event-app/LiveStreamViewController.swift

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,52 @@
2424
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2525
// THE SOFTWARE.
2626
//
27+
28+
// YouTubeiOSPlayerHelper
29+
//
30+
// Licensed under the Apache License, Version 2.0 (the "License");
31+
// you may not use this file except in compliance with the License.
32+
// You may obtain a copy of the License at
33+
//
34+
// http://www.apache.org/licenses/LICENSE-2.0
35+
//
36+
// Unless required by applicable law or agreed to in writing, software
37+
// distributed under the License is distributed on an "AS IS" BASIS,
38+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39+
// See the License for the specific language governing permissions and
40+
// limitations under the License.
41+
2742
import UIKit
43+
import YouTubeiOSPlayerHelper
2844

2945
class LiveStreamViewController: UIViewController {
3046
override func viewDidLoad() {
3147
super.viewDidLoad()
48+
49+
let playerView = YTPlayerView()
50+
playerView.delegate = self
51+
playerView.translatesAutoresizingMaskIntoConstraints = false
3252

33-
let streamViewLabel = UILabel()
34-
streamViewLabel.translatesAutoresizingMaskIntoConstraints = false
35-
streamViewLabel.text = "Stream view"
36-
streamViewLabel.textColor = .lightText
37-
streamViewLabel.font = UIFont(name: "Poppins-Light", size: 18)
38-
streamViewLabel.sizeToFit()
53+
view.addSubview(playerView)
3954

40-
view.addSubview(streamViewLabel)
55+
playerView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
56+
playerView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
57+
playerView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
58+
playerView.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
4159

42-
streamViewLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
43-
streamViewLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
60+
playerView.load(
61+
withVideoId: "b42bhUfcLxc",
62+
playerVars: ["playsinline": 1]
63+
)
64+
}
65+
}
66+
67+
extension LiveStreamViewController: YTPlayerViewDelegate {
68+
func playerViewDidBecomeReady(_ playerView: YTPlayerView) {
69+
playerView.playVideo()
70+
}
71+
72+
func playerView(_ playerView: YTPlayerView, receivedError error: YTPlayerError) {
73+
debugPrint("The player view received an error: \(error)")
4474
}
4575
}

0 commit comments

Comments
 (0)