mirror of https://github.com/mpv-player/mpv
examples/cocoabasic: allow to send stop command
This commit is contained in:
parent
b742384162
commit
721e430cd2
|
@ -59,7 +59,9 @@ static void wakeup(void *);
|
||||||
NSMenuItem *item = [m addItemWithTitle:@"Apple" action:nil keyEquivalent:@""];
|
NSMenuItem *item = [m addItemWithTitle:@"Apple" action:nil keyEquivalent:@""];
|
||||||
NSMenu *sm = [[NSMenu alloc] initWithTitle:@"Apple"];
|
NSMenu *sm = [[NSMenu alloc] initWithTitle:@"Apple"];
|
||||||
[m setSubmenu:sm forItem:item];
|
[m setSubmenu:sm forItem:item];
|
||||||
[sm addItemWithTitle: @"Shutdown mpv" action:@selector(shutdown) keyEquivalent:@"s"];
|
[sm addItemWithTitle: @"mpv_command('stop')" action:@selector(mpv_stop) keyEquivalent:@""];
|
||||||
|
[sm addItemWithTitle: @"mpv_command('quit')" action:@selector(mpv_quit) keyEquivalent:@""];
|
||||||
|
[sm addItemWithTitle: @"quit" action:@selector(terminate:) keyEquivalent:@"q"];
|
||||||
[NSApp setMenu:m];
|
[NSApp setMenu:m];
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
}
|
}
|
||||||
|
@ -122,24 +124,23 @@ static void wakeup(void *);
|
||||||
- (void) handleEvent:(mpv_event *)event
|
- (void) handleEvent:(mpv_event *)event
|
||||||
{
|
{
|
||||||
switch (event->event_id) {
|
switch (event->event_id) {
|
||||||
case MPV_EVENT_SHUTDOWN:
|
case MPV_EVENT_SHUTDOWN: {
|
||||||
// Clean up and shut down.
|
mpv_detach_destroy(mpv);
|
||||||
mpv_terminate_destroy(mpv);
|
|
||||||
mpv = NULL;
|
mpv = NULL;
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
printf("event: shutdown\n");
|
||||||
[[NSApplication sharedApplication] terminate:nil];
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case MPV_EVENT_LOG_MESSAGE: {
|
case MPV_EVENT_LOG_MESSAGE: {
|
||||||
struct mpv_event_log_message *msg = (struct mpv_event_log_message *)event->data;
|
struct mpv_event_log_message *msg = (struct mpv_event_log_message *)event->data;
|
||||||
printf("[%s] %s: %s", msg->prefix, msg->level, msg->text);
|
printf("[%s] %s: %s", msg->prefix, msg->level, msg->text);
|
||||||
}
|
}
|
||||||
|
|
||||||
case MPV_EVENT_VIDEO_RECONFIG:
|
case MPV_EVENT_VIDEO_RECONFIG: {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[self->w selectNextKeyView:nil];
|
[self->w selectNextKeyView:nil];
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("event: %s\n", mpv_event_name(event->event_id));
|
printf("event: %s\n", mpv_event_name(event->event_id));
|
||||||
|
@ -166,13 +167,18 @@ static void wakeup(void *context) {
|
||||||
// Ostensibly, mpv's window would be hooked up to this.
|
// Ostensibly, mpv's window would be hooked up to this.
|
||||||
- (BOOL) windowShouldClose:(id)sender
|
- (BOOL) windowShouldClose:(id)sender
|
||||||
{
|
{
|
||||||
[self shutdown];
|
return NO;
|
||||||
if (self->w)
|
|
||||||
[self->w release];
|
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) shutdown
|
- (void) mpv_stop
|
||||||
|
{
|
||||||
|
if (mpv) {
|
||||||
|
const char *args[] = {"stop", NULL};
|
||||||
|
mpv_command(mpv, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) mpv_quit
|
||||||
{
|
{
|
||||||
if (mpv) {
|
if (mpv) {
|
||||||
const char *args[] = {"quit", NULL};
|
const char *args[] = {"quit", NULL};
|
||||||
|
|
Loading…
Reference in New Issue