Skip to content

Commit 4c1b27b

Browse files
authored
iOS: simpler movieplayer example + retain/transfer fix (#7608)
#changelog #ios
1 parent 1837cd0 commit 4c1b27b

5 files changed

Lines changed: 126 additions & 1 deletion

File tree

addons/ofxiOS/src/video/ofxiOSVideoPlayer.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
bool ofxiOSVideoPlayer::load(string name) {
4242

4343
if(!videoPlayer) {
44-
videoPlayer = (__bridge void *)[[AVFoundationVideoPlayer alloc] init];
44+
videoPlayer = (__bridge_retained void *)[[AVFoundationVideoPlayer alloc] init];
4545
[(__bridge AVFoundationVideoPlayer *)videoPlayer setWillBeUpdatedExternally:YES];
4646
}
4747

@@ -86,6 +86,7 @@
8686

8787
((__bridge AVFoundationVideoPlayer *)videoPlayer).delegate = nil;
8888

89+
__autoreleasing AVFoundationVideoPlayer *player = (__bridge_transfer AVFoundationVideoPlayer *)videoPlayer;
8990
if(bTextureCacheSupported == true) {
9091
killTextureCache();
9192
}
1.51 MB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "ofApp.h"
2+
3+
int main() {
4+
5+
// here are the most commonly used iOS window settings.
6+
//------------------------------------------------------
7+
ofiOSWindowSettings settings;
8+
settings.enableRetina = false; // enables retina resolution if the device supports it.
9+
settings.enableDepth = false; // enables depth buffer for 3d drawing.
10+
settings.enableAntiAliasing = false; // enables anti-aliasing which smooths out graphics on the screen.
11+
settings.numOfAntiAliasingSamples = 0; // number of samples used for anti-aliasing.
12+
settings.enableHardwareOrientation = false; // enables native view orientation.
13+
settings.enableHardwareOrientationAnimation = false; // enables native orientation changes to be animated.
14+
settings.glesVersion = OFXIOS_RENDERER_ES1; // type of renderer to use, ES1, ES2, etc.
15+
16+
ofCreateWindow(settings);
17+
18+
return ofRunApp(new ofApp);
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include "ofxiOS.h"
4+
5+
class ofApp : public ofxiOSApp {
6+
7+
public:
8+
void setup();
9+
void update();
10+
void draw();
11+
void exit();
12+
13+
void touchDown(ofTouchEventArgs & touch);
14+
void touchMoved(ofTouchEventArgs & touch);
15+
void touchUp(ofTouchEventArgs & touch);
16+
void touchDoubleTap(ofTouchEventArgs & touch);
17+
void touchCancelled(ofTouchEventArgs & touch);
18+
19+
void lostFocus();
20+
void gotFocus();
21+
void gotMemoryWarning();
22+
void deviceOrientationChanged(int newOrientation);
23+
24+
ofVideoPlayer player_;
25+
26+
};
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "ofApp.h"
2+
3+
//--------------------------------------------------------------
4+
void ofApp::setup(){
5+
player_.load("hands.m4v");
6+
player_.play();
7+
}
8+
9+
//--------------------------------------------------------------
10+
void ofApp::update(){
11+
player_.update();
12+
13+
if (ofGetElapsedTimef() > 10) {
14+
player_.close();
15+
}
16+
}
17+
18+
//--------------------------------------------------------------
19+
void ofApp::draw(){
20+
ofBackground(0,0,0);
21+
if (player_.isLoaded()) {
22+
player_.draw(0,0);
23+
24+
} else {
25+
ofDrawBitmapString("Player was unloaded sucessfully after 10 seconds", 20,20);
26+
}
27+
}
28+
29+
//--------------------------------------------------------------
30+
void ofApp::exit(){
31+
32+
}
33+
34+
//--------------------------------------------------------------
35+
void ofApp::touchDown(ofTouchEventArgs & touch){
36+
37+
}
38+
39+
//--------------------------------------------------------------
40+
void ofApp::touchMoved(ofTouchEventArgs & touch){
41+
42+
}
43+
44+
//--------------------------------------------------------------
45+
void ofApp::touchUp(ofTouchEventArgs & touch){
46+
47+
}
48+
49+
//--------------------------------------------------------------
50+
void ofApp::touchDoubleTap(ofTouchEventArgs & touch){
51+
52+
}
53+
54+
//--------------------------------------------------------------
55+
void ofApp::touchCancelled(ofTouchEventArgs & touch){
56+
57+
}
58+
59+
//--------------------------------------------------------------
60+
void ofApp::lostFocus(){
61+
62+
}
63+
64+
//--------------------------------------------------------------
65+
void ofApp::gotFocus(){
66+
67+
}
68+
69+
//--------------------------------------------------------------
70+
void ofApp::gotMemoryWarning(){
71+
72+
}
73+
74+
//--------------------------------------------------------------
75+
void ofApp::deviceOrientationChanged(int newOrientation){
76+
77+
}
78+
79+

0 commit comments

Comments
 (0)