93eae203e42faff513793d6ae860c6b74ff93b29
[platform/upstream/gstreamer.git] / tutorials / xcode iOS / Tutorial 3 / ViewController.m
1 #import "ViewController.h"
2 #import "GStreamerBackend.h"
3 #import <UIKit/UIKit.h>
4
5 @interface ViewController () {
6     GStreamerBackend *gst_backend;
7     int media_width;
8     int media_height;
9 }
10
11 @end
12
13 @implementation ViewController
14
15 /*
16  * Methods from UIViewController
17  */
18
19 - (void)viewDidLoad
20 {
21     [super viewDidLoad];
22     
23     play_button.enabled = FALSE;
24     pause_button.enabled = FALSE;
25     
26     /* Make these constant for now, later tutorials will change them */
27     media_width = 320;
28     media_height = 240;
29
30     gst_backend = [[GStreamerBackend alloc] init:self videoView:video_view];
31 }
32
33 - (void)didReceiveMemoryWarning
34 {
35     [super didReceiveMemoryWarning];
36     // Dispose of any resources that can be recreated.
37 }
38
39 /* Called when the Play button is pressed */
40 -(IBAction) play:(id)sender
41 {
42     [gst_backend play];
43 }
44
45 /* Called when the Pause button is pressed */
46 -(IBAction) pause:(id)sender
47 {
48     [gst_backend pause];
49 }
50
51 - (void)viewDidLayoutSubviews
52 {
53     CGFloat view_width = video_container_view.bounds.size.width;
54     CGFloat view_height = video_container_view.bounds.size.height;
55
56     CGFloat correct_height = view_width * media_height / media_width;
57     CGFloat correct_width = view_height * media_width / media_height;
58
59     if (correct_height < view_height) {
60         video_height_constraint.constant = correct_height;
61         video_width_constraint.constant = view_width;
62     } else {
63         video_width_constraint.constant = correct_width;
64         video_height_constraint.constant = view_height;
65     }
66 }
67
68 /*
69  * Methods from GstreamerBackendDelegate
70  */
71
72 -(void) gstreamerInitialized
73 {
74     dispatch_async(dispatch_get_main_queue(), ^{
75         play_button.enabled = TRUE;
76         pause_button.enabled = TRUE;
77         message_label.text = @"Ready";
78     });
79 }
80
81 -(void) gstreamerSetUIMessage:(NSString *)message
82 {
83     dispatch_async(dispatch_get_main_queue(), ^{
84         message_label.text = message;
85     });
86 }
87
88 @end