-
-
Save hansemannn/68252eb5c106c2552d21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var window = Ti.UI.createWindow({ | |
title: "iOS 9.1 Live Photos", | |
backgroundColor: "#fff" | |
}); | |
var start = Ti.UI.createButton({ | |
title: "Start", | |
bottom: 10, | |
left: 10, | |
backgroundColor: "#fff" | |
}); | |
var stop = Ti.UI.createButton({ | |
title: "Stop", | |
bottom: 10, | |
right: 10, | |
backgroundColor: "#fff" | |
}); | |
window.add(start); | |
window.add(stop); | |
start.addEventListener("click", startPlayback); | |
stop.addEventListener("click", stopPlayback); | |
var view = null; | |
var nav = Ti.UI.iOS.createNavigationWindow({ | |
window: window | |
}); | |
var btn1 = Ti.UI.createButton({ | |
systemButton: Ti.UI.iPhone.SystemButton.ADD, | |
top:30 | |
}); | |
btn1.addEventListener("click", openGallery); | |
var btn2 = Ti.UI.createButton({ | |
systemButton: Ti.UI.iPhone.SystemButton.TRASH, | |
top:10 | |
}); | |
btn2.addEventListener("click", resetImageView); | |
window.setRightNavButton(btn1); | |
window.setLeftNavButton(btn2); | |
nav.open(); | |
function openGallery() { | |
Ti.Media.openPhotoGallery({ | |
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO, Ti.Media.MEDIA_TYPE_LIVEPHOTO], | |
success: function(e) { | |
var photo = e.media; // Static photo without motion of type Ti.Blob | |
var livePhoto = e.livePhoto // Live photo of type Ti.UI.iOS.LivePhoto | |
Ti.API.warn(e.mediaType); // Should display "com.apple.live-photo" when a live photo is selected | |
if(livePhoto) { | |
// Live photo supported and returned | |
view = Ti.UI.iOS.createLivePhotoView({ | |
livePhoto: livePhoto, | |
backgroundColor: "#f00" | |
}); | |
view.addEventListener("start", function(e) { | |
Ti.API.warn("Start playback"); | |
Ti.API.warn(e); | |
}); | |
view.addEventListener("stop", function(e) { | |
Ti.API.warn("Stop playback"); | |
Ti.API.warn(e); | |
}); | |
} else if (photo && e.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) { | |
// Default photo for iOS < 9.1 | |
view = Ti.UI.createImageView({ | |
image: photo | |
}); | |
} else { | |
Ti.API.warn("Fallback: Most probably selected video (not part of this example)."); | |
return; | |
} | |
window.add(view); | |
} | |
}); | |
} | |
function startPlayback() { | |
if (view) { | |
view.startPlaybackWithStyle(Ti.UI.iOS.LIVEPHOTO_PLAYBACK_STYLE_FULL); | |
} else { | |
Ti.API.warn("LiveView not created (yet)"); | |
} | |
} | |
function stopPlayback() { | |
if (view) { | |
view.stopPlayback(); | |
} else { | |
Ti.API.warn("LiveView not created (yet)"); | |
} | |
} | |
function resetImageView() { | |
var children = window.children; | |
for(var i = 0; i < children.length; i++) { | |
var child = children[i]; | |
window.remove(child); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment