function ShowFinalMovieFunction(movName,finalMoviePauseTime)
% ShowFinalMovieFunction plays the  movie
%
%%%%%%% Arguments:
% movName [string]: name of movie to show
% finalMoviePauseTime [double OR 'default']: number of second pause between frame for FINAL movie
    % (sorted legs in different colors)
        % default = .03
    
    
if isequal(finalMoviePauseTime,'default')
    finalMoviePauseTime = .03;
end

close

workingDir = tempname;
mkdir(workingDir);
mkdir(workingDir,'images');

% % Load final tracked movie
movFinal = VideoReader(movName);
numFrames = movFinal.NumberOfFrames; %#ok<*VIDREAD>

for i = 1:numFrames
    img = read(movFinal,i);
    imwrite(img,fullfile(workingDir,'images',sprintf('img%d.jpg',i)));
end

imageNames = dir(fullfile(workingDir,'images','*.jpg'));
imageNames = {imageNames.name}';

imageStrings = regexp([imageNames{:}],'(\d*)','match');
imageNumbers = str2double(imageStrings);

[~,sortedIndices] = sort(imageNumbers);
sortedImageNames = imageNames(sortedIndices);

for i = 1:numFrames
    finalImage = imread(fullfile(workingDir,'images',sortedImageNames{i}));

    imshow(finalImage)
    pause(finalMoviePauseTime)
    hold off
end