Baffling video problem

In my app, the user first loads a video into a moviePlayer. He is then prompted to save his project. This has always worked fine until recently. After loading some videos, the save dialog box will come up and if you click Save, it will fail to save the project (just a text file). It’s only some videos, though, and I cannot seem to figure out why. I’ve tried re-exporting the video as H.264 with AAC audio and that usually works fine, but there seems to be something in the video preventing my app from being able to save the project file. The movie loads into the moviePlayer fine and reports back the movie duration, name, file path, height and width, etc. I have no clue what’s causing this, though. Here is the code for my SaveAs method. When these problematic movies are in the moviePlayer, it will not create the folderItem. I have that commented below. (code edited somewhat for brevity)

[code]dim f as folderItem
dim t as textoutputStream
dim i,count as integer
dim timeCode, text, seconds, txtFont, txtSize, txtStyle, txtColor, colorIndex, fontIndex, interval,sccRow as string
dim rg as New RegEx
dim myMatch as RegExMatch

dim dlg as New SaveAsDialog
dlg.InitialDirectory = getFolderItem(app.movieTextPath)//SpecialFolder.Documents
dlg.promptText = “Please save your project so the auto-save feature can work.”
dim filename() as string
dim subFilename() as string

rg.searchPattern = “:$”

for i = 0 to editorWin.ListBox1.ListCount-1

myMatch =,2))

if myMatch <> nil then
editorWin.listBox1.cell(i,2) = editorWin.listBox1.cell(i,2)+ " "
end if


rg.searchPattern = “\r”

if app.lang = “” then
app.lang = “en”
end if

if app.movieName <> “” then
filename = Split(app.movieName, “.”)
dlg.SuggestedFileName = filename(0) + “.mcpt”

dlg.SuggestedFileName = “myProject.mcpt”
end if

app.textFieldSize = editorWin.bkgdHeight.text

dlg.Title = “Save Your Project”


f = dlg.ShowModal()

if f <> nil then

t = f.createtextFile

/// t is nil for the problematic movies. I get the Else code running below when these are loaded.
/// it will never save the file later even if i click cancel and then try to save later.

if t <> nil then ////// This works for most movies.

if app.movieName <> "" then
  t.writeLine app.movieName
  t.writeLine app.movieWidth
  t.writeLine app.movieHeight
  t.writeLine str(app.movieDuration)
  //msgBox "app.movieDuration = " + str(app.movieDuration)
  t.writeLine app.totalMovieTime
  t.writeLine app.filePath
  t.writeLine "No movie selected"
  t.writeLine "NA"
  t.writeLine "NA"
  t.writeLine "NA"
  t.writeLine "NA"
  t.writeLine "NA"
end if
t.writeLine timeCode
//msgBox "timecode = " + timecode
t.writeLine text
t.writeLine seconds
t.writeLine txtFont
t.writeLine txtSize
t.writeLine txtStyle
t.writeLine txtColor
t.writeLine colorIndex
t.writeLine fontIndex
t.writeLine app.bgdColor
if val(app.trackPosition) > 0 then
  t.writeLine app.trackPosition
  t.writeLine "40"
end if
t.writeLine interval
t.writeLine editorWin.bkgdHeight.text
t.writeLine app.maxChar
t.writeLine app.lang
t.writeLine app.keyed
t.writeLine sccRow
t.writeLine app.moviePath

else //// problematic movies trigger this even if the file is saved to the Desktop…

msgBox "There was a problem saving the file." + endOfLine+ endOfLine + "Do you have read/write access to  this folder or drive?"  + endOfLine + endOfLine +  "Try doing a Save As to a different location."

end if

app.savedFilePath = f.absolutePath
editorWin.title = “Project: " +
app.projectName =
app.projectName = replace(app.projectName,”.mcpt","")
app.changes = 0

//msgBox “Since you chose not to save this project, you will need to use the Save As… option under the File menu after you add your first caption.”
app.changes = 1
end if


Why would loading a movie prevent the app from merely writing a text file???

What do you mean with “click Save, it will fail to save the project”?

Probably that f.CreateTextfile returns nil.

Patrick, if you can reproduce it, then check the permissions of the folder in which you want to create the file, and also check if there’s already a file of that name, which may be somehow locked, so you can’t overwrite it.

I do not even see CREATETEXTFILE as a FolderItem method?

I use


I’m using t = f.createtextFile to create the text file.

This is pretty weird, but the movie I’m loading is on the Desktop. If I try to save my text file to the Desktop, even with a different name than the movie, it will fail to save (returns nil). I can’t even create a New Folder from the dialog box and save it to the Desktop. It will fail to create the new folder too (named “untitled folder”). BUT I can switch to another folder like Documents and it will save both the text file and a subfolder (I did both). It seems like it won’t save the text file into the same folder as the movie for some crazy reason. I’ve tried moving movies around from the Movies folder to the Desktop and that seems to be the pattern. Was also able to save the text file to a mounted drive. So perhaps it has nothing to do with the movie itself, but that it can’t save to the same folder as the movie.

tried creating a sample app with just the load movie action and the save, but i can’t seem to recreate the problem. i’ll somehow have to figure out what’s going on in my code. just not sure where to concentrate.

FolderItem.CreateTextFile was deprecated in 2012, start there as the operating system is more asynchronous than it used to be. File actions can happen asynchronously and the Xojo framework literally needs to wait. It may just be old code. You may find more luck with using GetTemporaryFolderItem instead of CreateTextFile. Move the resulting files into place after the fact.

YMMV though, this one’s tricky without seeing the project.

I think i tracked it down. I replaced

dlg.InitialDirectory = getFolderItem(app.movieTextPath)


dlg.InitialDirectory = SpecialFolder.Documents

and now it seems to be able to write to the same folder as the movie (after I change it to the Desktop).
I originally had Documents as the initialDirectory, but I think I changed it when a customer wanted to be able to save to the same folder as they got their movie from. I had Documents commented out, but I guess I never suspected that’s what it was.
How could I make initialDirectory the same folder as the movie?

The reason that’s working is because of the odd behavior you noticed in which changing the directory frees things up. I don’t think setting InitialDirectory to Documents is the real solution. I think it’s just a hacky band-aid for whatever the real problem is.

Instead of turning the movie FolderItem into a path, keep the actual FolderItem. Then, you can set the InitialDrectory to fMovieFolderItem.Parent (to be the parent directory of the movie, and not the movie file itself).

I would be curious to see if that change corrects the behavior.

Edit: FWIW we don’t have this problem in SRT Creator, which offers the same “save a sidecar file next to the movie source” function.

thanks. I’ll give that a try tomorrow. whether it was a hack or not, Documents was how I originally had initialDirectory for quite sometime. will be interesting to see if that would fix it.

The Java app? Or do you have a link?

@Markus Winter:

That worked well, @Tim Parnell. Thanks for that suggestion, and thanks to others who commented as well.