Skip to content

Commit

Permalink
Merge pull request #48 from NathanaelA/textureview
Browse files Browse the repository at this point in the history
Revamped Android Video player to use TextureView rather than SurfaceView
  • Loading branch information
bnussey authored Dec 15, 2016
2 parents 6150118 + e07650e commit 925d037
Show file tree
Hide file tree
Showing 4 changed files with 433 additions and 131 deletions.
2 changes: 2 additions & 0 deletions demo/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
margin: 20;
}


button {
horizontal-align: center;
}
Expand All @@ -12,6 +13,7 @@ button {
font-size: 20;
color: #284848;
horizontal-align: center;
margin-right: 5;
}

ActionBar {
Expand Down
22 changes: 12 additions & 10 deletions demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
<ActionBar title="Native Video" />
<ScrollView>
<StackLayout>
<StackLayout orientation="horizontal" margin="10">
<GridLayout rows="auto" columns="auto,*,auto,auto" margin="10">

<Label text="Current Time: " textWrap="true" />
<Label text="{{ currentTime }}" class="message" textWrap="true" />
</StackLayout>
<StackLayout orientation="horizontal" margin="10">
<Label text="Video Duration: " 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" />
<Label col="1" text="{{ currentTime }}" class="message" textWrap="true" />

<Label col="2" text="Video Duration: " textWrap="true" />
<Label col="3" text="{{ videoDuration }}" class="message" textWrap="true" />
</GridLayout>
<GridLayout rows="*" columns="*, *" backgroundColor="#000000">
<Video:Video id="nativeVideoPlayer" controls="true" loadingComplete="{{ videoCompleted }}" finished="{{ videoFinished }}" loop="false" autoplay="false" height="280" src="~/videos/big_buck_bunny.mp4" row="0" colSpan="2"/>
<Label text="Label On Top of Video View" row="0" colSpan="2" color="#fff" horizontalAlignment="center"/>
</GridLayout>
<StackLayout orientation="horizontal">
<Button text="Pause" width="33%" tap="{{ pauseVideo }}" />
Expand All @@ -28,6 +28,8 @@
<Button text="UnMute" width="33%" tap="{{ unmuteVideo }}" />
<Button text="Go to 30 seconds" width="33%" tap="{{ goToTime }}" />
</StackLayout>

<Button text="Animate" width="33%" tap="{{ animate }}"/>
</StackLayout>
</ScrollView>
</Page>
Expand Down
58 changes: 52 additions & 6 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ export class HelloWorldModel extends Observable {
public currentTime: any;
public videoDuration: any;
private _videoPlayer: Video;
private completed: boolean;

constructor(mainpage: Page) {
super();

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

/**
* Video Finished callback
*/
public videoFinished(args) {
console.log('video finished event executed');
this.completed = true;
}



/**
* Pause the video
*/
Expand All @@ -43,7 +45,7 @@ export class HelloWorldModel extends Observable {
*/
public playVideo() {
this._videoPlayer.play();
this.set('videoDuration', this._videoPlayer.getDuration());
this.completed = false;
}


Expand Down Expand Up @@ -79,6 +81,44 @@ export class HelloWorldModel extends Observable {
}


public animate() {
console.log("Animation");

const enums = require("ui/enums");
this._videoPlayer.animate({
rotate: 360,
duration: 3000,
curve: enums.AnimationCurve.spring
}).then( () => {
return this._videoPlayer.animate({
rotate: 0,
duration: 3000,
curve: enums.AnimationCurve.spring
});
}).then( () => {
return this._videoPlayer.animate({
scale: {x: .5, y: .5},
duration: 1000,
curve: enums.AnimationCurve.spring
});

}).then( () => {
return this._videoPlayer.animate({
scale: {x: 1.5, y: 1.5},
duration: 3000,
curve: enums.AnimationCurve.spring
});
}).then( () => {
return this._videoPlayer.animate({
scale: {x: 1.0, y: 1.0},
duration: 3000,
curve: enums.AnimationCurve.spring
});

});

}

public muteVideo() {
this._videoPlayer.mute(true);
}
Expand Down Expand Up @@ -118,13 +158,19 @@ export class HelloWorldModel extends Observable {


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

}

Expand Down
Loading

0 comments on commit 925d037

Please sign in to comment.