Skip to content

Commit

Permalink
fix iOS demo crash
Browse files Browse the repository at this point in the history
  • Loading branch information
bradmartin committed Aug 18, 2016
1 parent a6ef44f commit 626bdda
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 62 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
*.js
*.js.map
*.log
*.d.ts
!index.d.ts
demo/lib
demo/app/*.js
demo/*.d.ts
demo/platforms
demo/node_modules
demo/.vscode
node_modules
screens/
.vscode/
*.DS_Store
17 changes: 10 additions & 7 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# generated files
.vs
.vs/
.sln
*.sln
demo/
demo/
screens/
app/
.vscode/
*.png
*.log
*.log
*.ts
!index.d.ts
!videoplayer.d.ts
!video-source/video-source.d.ts
tsconfig.json
README.md
36 changes: 16 additions & 20 deletions demo/app/main-page.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ import { Video } from 'nativescript-videoplayer';
export function pageLoaded(args: EventData) {
// Get the event sender
let page = <Page>args.object;
page.bindingContext = new HelloWorldModel(page);

if (isAndroid && device.sdkVersion >= "21") {
let window = android.startActivity.getWindow();
window.setStatusBarColor(new Color("#d32f2f").android);
}

setTimeout(function () {
let videoPlayer = topmost().getViewById('nativeVideoPlayer');
page.bindingContext = new HelloWorldModel(videoPlayer);
}, 0);

}
23 changes: 5 additions & 18 deletions demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,26 @@
<ActionBar title="Native Video" />
<ScrollView>
<StackLayout>

<StackLayout orientation="horizontal" margin="10">
<Label text="Current Time: " textWrap="true" />
<Label text="{{ currentTime }}" class="message" textWrap="true" />
<Label text="Video Duration: " textWrap="true" />
<Label text="{{ videoDuration }}" class="message" textWrap="true" />
<Label text="{{ videoDuration }}" class="message" textWrap="true" />
</StackLayout>

<GridLayout rows="*" columns="*, *">
<Label text="Label On Top of Video View" row="0" colSpan="2" color="#fff" horizontalAlignment="center" />

<Video:Video id="nativeVideoPlayer"
controls="true" finished="{{ videoFinished }}"
loop="true" autoplay="false" height="280"
src="~/videos/big_buck_bunny.mp4"
row="0" colSpan="2" />

<Video:Video id="nativeVideoPlayer" controls="true" finished="{{ videoFinished }}" loop="true" autoplay="false" height="280" src="~/videos/big_buck_bunny.mp4" row="0" colSpan="2" />
</GridLayout>

<StackLayout orientation="horizontal">
<Button text="Pause" width="33%" tap="{{ pauseVideo }}" />
<Button text="Play" width="33%" tap="{{ playVideo }}" />
<Button text="Stop" width="33%" tap="{{ stopVideo }}" />
<android>
<Button text="Stop" width="33%" tap="{{ stopVideo }}" />
</android>
</StackLayout>

<StackLayout orientation="horizontal">
<Button text="Go to 30 seconds" width="50%" tap="{{ goToTime }}" />
</StackLayout>

<!--<StackLayout orientation="horizontal">
<Button text="Change Video" width="50%" tap="{{ changeVideoSource }}" />
</StackLayout>-->

</StackLayout>
</ScrollView>
</Page>
Expand Down
25 changes: 18 additions & 7 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Observable } from 'data/observable';
import { EventData } from 'data/observable';
import { Page } from 'ui/page';
import { isAndroid, isIOS } from 'platform';
import { topmost } from 'ui/frame';
import { setInterval } from "timer";
import { Video } from 'nativescript-videoplayer';

Expand All @@ -9,13 +12,14 @@ export class HelloWorldModel extends Observable {
public videoDuration: any;
private _videoPlayer: Video;

constructor(videoPlayer: Video) {
constructor(mainpage: Page) {
super();

this._videoPlayer = videoPlayer;
this._videoPlayer = <Video>mainpage.getViewById('nativeVideoPlayer');
this.currentTime = '';
this.videoDuration = '';
this.trackVideoCurrentPosition();
this.getVideoDuration();
// this.trackVideoCurrentPosition();
}

/**
Expand Down Expand Up @@ -47,7 +51,9 @@ export class HelloWorldModel extends Observable {
* Stop the video player
*/
public stopVideo() {
this._videoPlayer.stop();
if (isAndroid) {
this._videoPlayer.stop();
}
}


Expand All @@ -57,6 +63,7 @@ export class HelloWorldModel extends Observable {
public getVideoDuration() {
let videoDuration = this._videoPlayer.getDuration();
console.log('Video Duration: ' + videoDuration);
this.set('videoDuration', videoDuration);
}


Expand All @@ -65,7 +72,7 @@ export class HelloWorldModel extends Observable {
*/
public goToTime() {
try {
this._videoPlayer.seekToTime(30000);
this._videoPlayer.seekToTime(3000);
} catch (err) {
console.log(err);
}
Expand Down Expand Up @@ -103,10 +110,14 @@ export class HelloWorldModel extends Observable {


private trackVideoCurrentPosition(): number {
// if (isAndroid) {
let trackInterval = setInterval(() => {
this.set('currentTime', this._videoPlayer.getCurrentTime());
}, 100);
var x = this._videoPlayer.getCurrentTime();
this.set('currentTime', x);
}, 200);
return trackInterval;
// }

}


Expand Down
7 changes: 4 additions & 3 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"nativescript": {
"id": "org.nativescript.videoplayer",
"tns-android": {
"version": "2.1.1"
"version": "2.2.0"
},
"tns-ios": {
"version": "1.7.0"
"version": "2.2.1"
}
},
"dependencies": {
Expand All @@ -18,6 +18,7 @@
"babylon": "6.8.0",
"filewalker": "0.1.2",
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.3.2",
"typescript": "^1.8.10"
}
}
}
3 changes: 2 additions & 1 deletion demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"target": "es5",
"sourceMap": true,
"experimentalDecorators": true,
"noEmitHelpers": true
"noEmitHelpers": true,
"noEmitOnError": false
},
"exclude": [
"node_modules",
Expand Down

0 comments on commit 626bdda

Please sign in to comment.