Skip to content

Commit

Permalink
feat(demo): add sync player
Browse files Browse the repository at this point in the history
  • Loading branch information
skufly authored and pingkai committed Apr 30, 2020
1 parent c854037 commit 6177474
Show file tree
Hide file tree
Showing 9 changed files with 430 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
9282EB4C22168F410032F3DF /* RightView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9282EB4B22168F410032F3DF /* RightView.m */; };
9282EB4E22168F520032F3DF /* RightView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9282EB4D22168F520032F3DF /* RightView.xib */; };
92B040CD222788C800FFA403 /* ConfigSetView.m in Sources */ = {isa = PBXBuildFile; fileRef = 92B040CC222788C800FFA403 /* ConfigSetView.m */; };
9E66A3B82451751600EBFDE4 /* MutlPlayViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E66A3B72451751600EBFDE4 /* MutlPlayViewController.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -210,6 +211,8 @@
9282EB4D22168F520032F3DF /* RightView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RightView.xib; sourceTree = "<group>"; };
92B040CB222788C800FFA403 /* ConfigSetView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ConfigSetView.h; sourceTree = "<group>"; };
92B040CC222788C800FFA403 /* ConfigSetView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ConfigSetView.m; sourceTree = "<group>"; };
9E66A3B62451751600EBFDE4 /* MutlPlayViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MutlPlayViewController.h; sourceTree = "<group>"; };
9E66A3B72451751600EBFDE4 /* MutlPlayViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MutlPlayViewController.m; sourceTree = "<group>"; };
B97ADCAB94193F6589D4DA69 /* Pods-AliPlayerDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AliPlayerDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AliPlayerDemo/Pods-AliPlayerDemo.debug.xcconfig"; sourceTree = "<group>"; };
D622A9A7E2A93156E086DEFA /* Pods-CicadaDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CicadaDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-CicadaDemo/Pods-CicadaDemo.release.xcconfig"; sourceTree = "<group>"; };
E9E63D7913B0D1BB3B3E4672 /* Pods-AliPlayerDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AliPlayerDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-AliPlayerDemo/Pods-AliPlayerDemo.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -342,6 +345,8 @@
92560B8C21FED4E4001244CA /* AliPlayerViewController.m */,
9282EB3F221650010032F3DF /* RootViewController.h */,
9282EB40221650010032F3DF /* RootViewController.m */,
9E66A3B62451751600EBFDE4 /* MutlPlayViewController.h */,
9E66A3B72451751600EBFDE4 /* MutlPlayViewController.m */,
);
path = controller;
sourceTree = "<group>";
Expand Down Expand Up @@ -605,6 +610,7 @@
1F940555239DFA9F00F07BEE /* CicadaConfig+refresh.m in Sources */,
92560B8D21FED4E4001244CA /* AliPlayerViewController.m in Sources */,
92560B9321FEE28C001244CA /* AVBottomView.m in Sources */,
9E66A3B82451751600EBFDE4 /* MutlPlayViewController.m in Sources */,
92560B8A21FEB2AE001244CA /* AVPBaseViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="15400" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15505"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15400"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -679,7 +679,7 @@
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="0.0"/>
<point key="canvasLocation" x="378" y="-120"/>
</scene>
<!--Window Controller-->
<scene sceneID="R2V-B0-nI4">
Expand All @@ -700,7 +700,7 @@
</windowController>
<customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="250"/>
<point key="canvasLocation" x="75" y="179"/>
</scene>
<!--Root View Controller-->
<scene sceneID="a0S-sD-0oP">
Expand Down Expand Up @@ -755,7 +755,7 @@
</viewController>
<customObject id="ZeP-v0-cew" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-74" y="738"/>
<point key="canvasLocation" x="75" y="647"/>
</scene>
<!--Window Controller-->
<scene sceneID="sQI-6f-rar">
Expand All @@ -776,7 +776,7 @@
</windowController>
<customObject id="GxD-d3-PNi" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-22" y="1095"/>
<point key="canvasLocation" x="687" y="179"/>
</scene>
<!--Window Controller-->
<scene sceneID="VRi-QA-N79">
Expand All @@ -797,7 +797,41 @@
</windowController>
<customObject id="zuE-Yr-7g9" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-32" y="1576"/>
<point key="canvasLocation" x="75" y="1137"/>
</scene>
<!--Window Controller-->
<scene sceneID="gAJ-nl-q7R">
<objects>
<windowController storyboardIdentifier="MultWindow" id="nmh-7l-jWn" sceneMemberID="viewController">
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="oyF-OJ-97a">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<connections>
<outlet property="delegate" destination="nmh-7l-jWn" id="EZu-Mt-JS8"/>
</connections>
</window>
<connections>
<segue destination="5jI-qR-KhO" kind="relationship" relationship="window.shadowedContentViewController" id="CF6-ga-0vj"/>
</connections>
</windowController>
<customObject id="UQZ-bl-pfz" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="1534"/>
</scene>
<!--Mutl Play View Controller-->
<scene sceneID="cby-4K-duW">
<objects>
<viewController storyboardIdentifier="MutlPlayViewController" id="5jI-qR-KhO" customClass="MutlPlayViewController" sceneMemberID="viewController">
<view key="view" id="kFs-uY-rOf">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
</view>
</viewController>
<customObject id="bEn-36-DNw" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="705" y="1534"/>
</scene>
<!--Simple Player View Controller-->
<scene sceneID="xKh-Ho-tv0">
Expand Down Expand Up @@ -846,7 +880,7 @@
</viewController>
<customObject id="YAZ-Wn-oqL" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="523" y="1474"/>
<point key="canvasLocation" x="705" y="1129"/>
</scene>
<!--Ali Player View Controller-->
<scene sceneID="hIz-AP-VOD">
Expand Down Expand Up @@ -893,7 +927,7 @@
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-576" y="1087"/>
<point key="canvasLocation" x="687" y="662"/>
</scene>
</scenes>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// MutlPlayViewController.h
// CicadaDemo
//
// Created by ToT on 2020/4/23.
// Copyright © 2020 com.alibaba. All rights reserved.
//

#import <Cocoa/Cocoa.h>

NS_ASSUME_NONNULL_BEGIN

@interface MutlPlayViewController : NSViewController

@property (nonatomic,strong)NSArray <CicadaUrlSource *>*urlSourceArray;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
//
// MutlPlayViewController.m
// CicadaDemo
//
// Created by ToT on 2020/4/23.
// Copyright © 2020 com.alibaba. All rights reserved.
//

#import "MutlPlayViewController.h"
#import "AppDelegate.h"
#import <CicadaPlayerSDK/CicadaSyncPlayerServer.h>
#import <CicadaPlayerSDK/CicadaSyncPlayerClient.h>

@interface MutlPlayViewController ()<CicadaDelegate>

@property (nonatomic,strong)NSMutableArray *playViewArray;
@property (nonatomic,strong)NSMutableArray *playersArray;
@property (nonatomic,assign)BOOL isFullScreen;
@property (nonatomic,assign)NSView *fullScreenView;
@property (nonatomic,assign)NSInteger viewWidth;
@property (nonatomic,assign)NSInteger viewHeight;
@property (nonatomic,strong)NSView *horizontalLine;
@property (nonatomic,strong)NSView *verticalLine;

@end

@implementation MutlPlayViewController

- (NSInteger)viewWidth {
AppDelegate *appdelegate = (AppDelegate *) [NSApplication sharedApplication].delegate;
NSWindow *window = appdelegate.mainWindow.window;
return window.frame.size.width;
}

- (NSInteger)viewHeight {
AppDelegate *appdelegate = (AppDelegate *) [NSApplication sharedApplication].delegate;
NSWindow *window = appdelegate.mainWindow.window;
return window.frame.size.height-22;
}

- (void)loadView {
NSView *view = [[NSView alloc]initWithFrame:NSMakeRect(0, 0, self.viewWidth, self.viewHeight)];
self.view = view;
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
}

- (void)viewDidAppear {
[super viewDidAppear];

self.horizontalLine = [[NSView alloc]init];
self.horizontalLine.wantsLayer = true;
self.horizontalLine.layer.backgroundColor = [NSColor redColor].CGColor;
[self.horizontalLine setNeedsDisplay:YES];
[self.view addSubview:self.horizontalLine];

self.verticalLine = [[NSView alloc]init];
self.verticalLine.wantsLayer = true;
self.verticalLine.layer.backgroundColor = [NSColor redColor].CGColor;
[self.verticalLine setNeedsDisplay:YES];
[self.view addSubview:self.verticalLine];

self.playersArray = [NSMutableArray array];
self.playViewArray = [NSMutableArray array];
for (int i = 0; i<4; i++) {
NSView *view = [[NSView alloc]init];
view.wantsLayer = true;
[view setNeedsDisplay:YES];

[self.view addSubview:view];
[self.playViewArray addObject:view];
}

NSPressGestureRecognizer *tap = [[NSPressGestureRecognizer alloc]initWithTarget:self action:@selector(viewTouches:)];
tap.minimumPressDuration = 0.01;
[self.view addGestureRecognizer:tap];

[self displayPrivateViews];

if (self.urlSourceArray.count == 4) {
for (int i = 0; i<4; i++) {
CicadaPlayer *player = nil;
if (0 == i) {
player = [[CicadaSyncPlayerServer alloc] init];
} else {
player = [[CicadaSyncPlayerClient alloc]init];
}

[player setUrlSource:self.urlSourceArray[i]];
player.delegate = self;
player.playerView = self.playViewArray[i];
[player prepare];
[self.playersArray addObject:player];
}
}
}

- (void)viewTouches:(NSPressGestureRecognizer *)recognizer {
if (recognizer.state == NSGestureRecognizerStateBegan) {
self.isFullScreen = !self.isFullScreen;
if (self.isFullScreen) {
NSPoint point = [recognizer locationInView:self.view];
NSInteger viewIndex = 0;
if (point.y > self.viewHeight/2) {
viewIndex = viewIndex + 2;
}
if (point.x > self.viewWidth/2) {
viewIndex = viewIndex + 1;
}
NSView *view = self.playViewArray[viewIndex];
[view removeFromSuperview];
view.frame = self.view.bounds;
[self.view addSubview:view];
[view setNeedsDisplay:YES];
self.fullScreenView = view;
}
[self displayPrivateViews];
}
}

- (void)viewDidDisappear {
[super viewDidDisappear];

for (CicadaPlayer *player in self.playersArray) {
[player stop];
[player destroy];
}
[self.playersArray removeAllObjects];
}

- (void)viewDidLayout {
[super viewDidLayout];

[self displayPrivateViews];
}

- (void)displayPrivateViews {
self.view.frame = NSMakeRect(0, 0, self.viewWidth, self.viewHeight);
[self.view setNeedsDisplay:YES];
if (self.isFullScreen) {
self.fullScreenView.frame = self.view.bounds;
[self.fullScreenView setNeedsDisplay:YES];
}else {
for (int i = 0; i<4; i++) {
NSView *view = self.playViewArray[i];
view.frame = NSMakeRect((i%2)*(self.viewWidth/2+1), (i/2)*(self.viewHeight/2+1), (self.viewWidth-2)/2, (self.viewHeight-2)/2);
[view setNeedsDisplay:YES];
}
}
self.horizontalLine.frame = NSMakeRect(0, self.viewHeight/2-1, self.viewWidth, 2);
[self.horizontalLine setNeedsDisplay:YES];
self.verticalLine.frame = NSMakeRect(self.viewWidth/2-1, 0, 2, self.viewHeight);
[self.verticalLine setNeedsDisplay:YES];
}

#pragma mark CicadaDelegate

- (void)onTrackReady:(CicadaPlayer *)player info:(NSArray<CicadaTrackInfo *> *)info {
//选择不同清晰度播放
// NSMutableArray * videoTracksArray = [NSMutableArray array];
// for (int i=0; i<info.count; i++) {
// CicadaTrackInfo* track = [info objectAtIndex:i];
// switch (track.trackType) {
// case CICADA_TRACK_VIDEO: {
// [videoTracksArray addObject:track];
// }
// break;
// default:
// break;
// }
// }
// NSInteger playerIndex = [self.playersArray indexOfObject:player];
// NSInteger trackInfoIndex = playerIndex % videoTracksArray.count;
// CicadaTrackInfo *track = videoTracksArray[trackInfoIndex];
// [player selectTrack:track.trackIndex];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ - (IBAction)showUrlLinks:(id)sender {
[self.rightView loadViewWithViewType:urlLinks];
}

- (IBAction)MultPlayer:(id)sender {
[self.rightView loadViewWithViewType:MultPlayer];
}

- (void)layout {
[super layout];
self.view.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height+ 50);
Expand Down
Loading

0 comments on commit 6177474

Please sign in to comment.