您还可以使用 TVML 和 TVMLJS
https://developer.apple.com/library/prerelease/tvos/documentation/TVMLJS/Reference/TVJSFrameworkReference/
遵守“TVApplicationControllerDelegate”协议并添加一些属性。
AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate, TVApplicationControllerDelegate>
...
@property (strong, nonatomic) TVApplicationController *appController;
@property (strong, nonatomic) TVApplicationControllerContext *appControllerContext;
然后将以下内容添加到'didFinishLaunchingWithOptions'
AppDelegate.m
#define url @"http://localhost:8000/main.js"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.appControllerContext = [[TVApplicationControllerContext alloc] init];
NSURL *javascriptURL = [NSURL URLWithString:url];
self.appControllerContext.javaScriptApplicationURL= javascriptURL;
for (id key in launchOptions) {
id val=[launchOptions objectForKey:key];
NSLog(@"key=%@ value=%@", key, val);
if([val isKindOfClass:[NSString class]]) [self.appControllerContext.launchOptions objectForKey:val];
self.appController = [[TVApplicationController alloc] initWithContext:self.appControllerContext window:self.window delegate:self];
}
return YES;
}
创建一个文件夹并添加以下文件
main.js
function launchPlayer() {
var player = new Player();
var playlist = new Playlist();
var mediaItem = new MediaItem("video", "http://trailers.apple.com/movies/focus_features/9/9-clip_480p.mov");
player.playlist = playlist;
player.playlist.push(mediaItem);
player.present();
//player.play()
}
//in application.js
App.onLaunch = function(options) {
launchPlayer();
}
小心mediaItem 中的这个url
设置您选择的模板。
索引.tvml
<document>
<alertTemplate>
<title>…</title>
<description>…</description>
<button>
<text>…</text>
</button>
<text>…</text>
</alertTemplate>
</document>
打开终端并导航到此文件夹然后运行
python -m SimpleHTTPServer 8000
确保此处的端口是您的 ObjC url 中的端口。Apple 示例使用 9001。
有关更多信息,请参阅这些教程
http://jamesonquave.com/blog/developing-tvos-apps-for-apple-tv-with-swift/
http://jamesonquave.com/blog/developing-tvos-apps-for-apple-tv-part- 2/
我遇到的一个问题是尝试播放本地视频文件。它不起作用,并且存在约束问题等。看起来您无法使用 python 播放视频,因此请尝试使用 apache 或链接到网络上的视频。这个SO answer 指向了我。