Last active
January 27, 2020 01:54
-
-
Save Gandum2077/a0348c7f924180397091fe9a54bdc02a to your computer and use it in GitHub Desktop.
改动使其支持播放本地和远程视频 JSBox video player based on AVPlayerViewController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const frameworks = ["AVFoundation", "AVKit"]; | |
frameworks.forEach(name => { | |
$objc("NSBundle").$bundleWithPath(`/System/Library/Frameworks/${name}.framework`).$load(); | |
}); | |
const gravities = { | |
resize: "AVLayerVideoGravityResize", | |
resizeAspect: "AVLayerVideoGravityResizeAspect", | |
resizeAspectFill: "AVLayerVideoGravityResizeAspectFill", | |
} | |
function play({ | |
url, | |
path, | |
showsPlaybackControls = true, | |
videoGravity = "resizeAspect", | |
allowsPictureInPicturePlayback = true, | |
updatesNowPlayingInfoCenter = true, | |
entersFullScreenWhenPlaybackBegins = false, | |
exitsFullScreenWhenPlaybackEnds = false, | |
}) { | |
if (!url && !path) return | |
const player = (path) | |
? $objc("AVPlayer").$playerWithURL($objc("NSURL").$fileURLWithPath($file.absolutePath(path))) | |
: $objc("AVPlayer").$playerWithURL($objc("NSURL").$URLWithString(url)); | |
player.$play(); | |
const playerVC = $objc("AVPlayerViewController").$new(); | |
playerVC.$setPlayer(player); | |
playerVC.$setShowsPlaybackControls(showsPlaybackControls); | |
playerVC.$setVideoGravity(gravities[videoGravity]); | |
playerVC.$setAllowsPictureInPicturePlayback(allowsPictureInPicturePlayback); | |
playerVC.$setUpdatesNowPlayingInfoCenter(updatesNowPlayingInfoCenter); | |
playerVC.$setEntersFullScreenWhenPlaybackBegins(entersFullScreenWhenPlaybackBegins); | |
playerVC.$setExitsFullScreenWhenPlaybackEnds(exitsFullScreenWhenPlaybackEnds); | |
const rootVC = $ui.controller.ocValue(); | |
rootVC.$presentViewController_animated_completion(playerVC, true, null); | |
} | |
exports.play = play; | |
// Example | |
const url = "https://images.apple.com/media/cn/ipad-pro/2017/43c41767_0723_4506_889f_0180acc13482/films/feature/ipad-pro-feature-cn-20170605_1280x720h.mp4"; | |
const path = "t.mp4"; | |
play({ | |
url: url, | |
//path: path, | |
showsPlaybackControls: true, | |
videoGravity: "resizeAspect", | |
allowsPictureInPicturePlayback: true, | |
updatesNowPlayingInfoCenter: false, | |
entersFullScreenWhenPlaybackBegins: false, | |
exitsFullScreenWhenPlaybackEnds: false | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment