Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25640] iOS: Ti.Media.VideoPlayer "playbackState" constants are undefined

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-01-17T09:21:18.000+0000
Affected Version/sRelease 7.0.0
Fix Version/sRelease 7.0.2
ComponentsiOS
Labelsios, videoplayer
ReporterMostafizur Rahman
AssigneeHans Knöchel
Created2018-01-02T17:54:33.000+0000
Updated2018-02-05T15:20:18.000+0000

Description

Hello, In iOS on SDK 7.0.0+, the playbackState constants are *undefined* (http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Media.VideoPlayer-property-playbackState). - Ti.Media.VIDEO_PLAYBACK_STATE_INTERRUPTED - Ti.Media.VIDEO_PLAYBACK_STATE_PAUSED - Ti.Media.VIDEO_PLAYBACK_STATE_PLAYING - Ti.Media.VIDEO_PLAYBACK_STATE_SEEKING_BACKWARD - Ti.Media.VIDEO_PLAYBACK_STATE_SEEKING_FORWARD - Ti.Media.VIDEO_PLAYBACK_STATE_STOPPED *Testing Environment:* Appcelerator Command-Line Interface, version 7.0.1 SDK: 7.0.1.GA iOS simulator: iPhone 7 *Test Code:*
var vidWin = Titanium.UI.createWindow({
    title : 'Video View Demo',
    backgroundColor : '#fff'
});
 
var videoPlayer = Titanium.Media.createVideoPlayer({
    top : 2,
    autoplay : true,
    backgroundColor : 'blue',
    height : 300,
    width : 300,
    mediaControlStyle : Titanium.Media.VIDEO_CONTROL_DEFAULT,
    scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FIT
});

// Log raw-values of constants
Ti.API.info('Titanium.Media.VIDEO_PLAYBACK_STATE_INTERRUPTED ' + Titanium.Media.VIDEO_PLAYBACK_STATE_INTERRUPTED);
Ti.API.info('Titanium.Media.VIDEO_PLAYBACK_STATE_PLAYING ' + Titanium.Media.VIDEO_PLAYBACK_STATE_PLAYING);
Ti.API.info('Titanium.Media.VIDEO_PLAYBACK_STATE_STOPPED ' + Titanium.Media.VIDEO_PLAYBACK_STATE_STOPPED);
 
videoPlayer.url = 'video.mp4';
vidWin.add(videoPlayer);
videoPlayer.addEventListener('playbackstate', function() {
 
  var message = 'Unknown';
  switch (videoPlayer.playbackState) {
    case Ti.Media.VIDEO_PLAYBACK_STATE_INTERRUPTED:
    message = 'Interrupted';
    break;
    case Ti.Media.VIDEO_PLAYBACK_STATE_PLAYING:
    message = 'Playing';
    break;
    case Ti.Media.VIDEO_PLAYBACK_STATE_PAUSED:
    message = 'Paused';
    break;
    case Ti.Media.VIDEO_PLAYBACK_STATE_STOPPED:
    message = 'Stopped';
  }
  
  Ti.API.info(message);    
});
 
vidWin.open();
*Test Results:*
[INFO] :   Titanium.Media.VIDEO_PLAYBACK_STATE_INTERRUPTED undefined
[INFO] :   Titanium.Media.VIDEO_PLAYBACK_STATE_PLAYING undefined
[INFO] :   Titanium.Media.VIDEO_PLAYBACK_STATE_SEEKING_BACKWARD undefined
[INFO] :   Titanium.Media.VIDEO_PLAYBACK_STATE_SEEKING_FORWARD undefined
[INFO] :   Titanium.Media.VIDEO_PLAYBACK_STATE_STOPPED undefined

Attachments

FileDateSize
video.mp42018-01-04T10:09:21.000+0000383631

Comments

  1. Hans Knöchel 2018-01-03

    As discussed yesterday, release 7.0.0 replaced the underlaying API of the Ti.Media.VideoPlayer (MPMoviePlayerController) with the most recent API (AVPlayerViewController) that has a slightly different API. [~vijaysingh] will have more insight here, but the newer way of getting the current video state is to use the playbackState property itself, rather than the constants. I think the docs still need to be updated there and some parity work was missing in the initial 7.0.0. Scheduling this ticket for 7.1.0 to address the documentation- and possible parity-issues. For this particular case: To check whether the movie is currently playing, check if the playbackState property returns a value > 0.
  2. Hans Knöchel 2018-01-04

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/9714 PR (7_0_X): https://github.com/appcelerator/titanium_mobile/pull/9715 Test-Case (use the attached mp4 file, as well as the test-case above):
       var win = Ti.UI.createWindow({
           backgroundColor: '#fff'
       });
       
       var video = Ti.Media.createVideoPlayer({
           url: 'video.mp4',
           height: 200
       });
       
       var btnPlay = Ti.UI.createButton({
         title: 'Play Video',
         top: 40
       });
       
       btnPlay.addEventListener('click', function(e) {
         video.play();
       });
       
       var btn = Ti.UI.createButton({
         title: 'Get current state',
         top: 100
       });
       
       btn.addEventListener('click', function(e) {
         var message = 'Unknown';
         
         switch (video.playbackState) {
           case Ti.Media.VIDEO_PLAYBACK_STATE_INTERRUPTED:
           message = 'Interrupted';
           break;
           case Ti.Media.VIDEO_PLAYBACK_STATE_PLAYING:
           message = 'Playing';
           break;
           case Ti.Media.VIDEO_PLAYBACK_STATE_PAUSED:
           message = 'Paused';
           break;
           case Ti.Media.VIDEO_PLAYBACK_STATE_STOPPED:
           message = 'Stopped';
         }
         
         Ti.API.info(message);
       });
       
       win.add(btnPlay);
       win.add(btn);
       win.add(video);
       
       win.open();
       
  3. Abir Mukherjee 2018-01-16

    FR passed.
  4. Abir Mukherjee 2018-01-24

    Verified fix is found in: SDK 7.0.2.v20180124113923 SDK 7.1.0.v20180124115505

JSON Source