Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1.  
  2. var window = Titanium.UI.createWindow({
  3. title: "Video Recorder",
  4. backgroundColor: 'black'
  5. });
  6. var b = Titanium.UI.createButton({
  7. title:'Record Movie',
  8. width:200,
  9. height:40,
  10. top:20
  11. });
  12.  
  13. b.addEventListener('click', function()
  14. {
  15. if (b.title == 'Play Movie')
  16. {
  17. Titanium.API.info('path = '+movieFile.nativePath);
  18. var activeMovie = Titanium.Media.createVideoPlayer({
  19. backgroundColor:'#111',
  20. movieControlMode:Titanium.Media.VIDEO_CONTROL_DEFAULT,
  21. scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FILL,
  22. //contentURL:movieFile.nativePath
  23. media:movieFile.nativePath // note you can use either contentURL to nativePath or the file object
  24. });
  25. activeMovie.play();
  26.  
  27. activeMovie.addEventListener('complete', function()
  28. {
  29. movieFile.deleteFile();
  30. b.title = 'Record Movie';
  31. });
  32.  
  33. if (parseFloat(Titanium.Platform.version) >= 3.2)
  34. {
  35. win.add(activeMovie);
  36. }
  37. }
  38. else
  39. {
  40. Titanium.Media.showCamera({
  41.  
  42. success:function(event)
  43. {
  44. var video = event.media;
  45. movieFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'mymovie.mov');
  46. movieFile.write(video);
  47. b.title = 'Play Movie';
  48. },
  49. cancel:function()
  50. {
  51.  
  52. },
  53. error:function(error)
  54. {
  55. // create alert
  56. var a = Titanium.UI.createAlertDialog({title:'Video'});
  57.  
  58. // set message
  59. if (error.code == Titanium.Media.NO_VIDEO)
  60. {
  61. a.setMessage('Device does not have video recording capabilities');
  62. }
  63. else
  64. {
  65. a.setMessage('Unexpected error: ' + error.code);
  66. }
  67.  
  68. // show alert
  69. a.show();
  70. },
  71. mediaTypes: Titanium.Media.MEDIA_TYPE_VIDEO,
  72. videoMaximumDuration:10000,
  73. videoQuality:Titanium.Media.QUALITY_HIGH
  74. });
  75.  
  76. }
  77.  
  78. });
  79.  
  80. window.add(b);
  81. window.open();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement