We have a MediaPlayer on a page that loads a mp4 file on Page_Load.
This works as the file is seen in the player interface and is playable. That same file can be replaced by the user on the same page with a RadAsyncUpload.
Unfortunately the MediaPlayer still seems to be holding on to the file as it throws the "...used by another process" error when the UploadedFile tries to overwrite the same file. Now we tried to remove the Source that is holding the file before we overwrite but it still doesnt work. The 'Clear()' function doesnt free up the file either.
We didnt load the file into the Source of the MediaPlayer on Page_Load and we were able to successfully overwrite the file. So rights are fine, it seems the MediaPlayer is locking onto the file even after we remove it from the Source.
Our clients can only save 1 file out, which they can overwrite with a new one. This works fine as long as the MediaPlayer doesnt have it added to its Source. We need it to be loaded on Page_Load and replaced at will via the RadAsyncUpload and 'swapped' out with the current Source(0).
Can you tell us how to 'free' up the file from the MediaPlayer so it can be overwritten and not locked?
Thanks!
myMediaPlayerSource.Path = <
PATH
>
Me.RadMediaPlayer1.Sources.Add(myMediaPlayerSource)
This works as the file is seen in the player interface and is playable. That same file can be replaced by the user on the same page with a RadAsyncUpload.
Me.RadMediaPlayer1.Sources.RemoveAt(0)
myUploadedFile.SaveAs(Server.MapPath(<
PATH
>), True)
' load it into the mediaplayersource
myMediaPlayerSource.Path = <
PATH
>
Me.RadMediaPlayer1.Sources.Add(myMediaPlayerSource)
Unfortunately the MediaPlayer still seems to be holding on to the file as it throws the "...used by another process" error when the UploadedFile tries to overwrite the same file. Now we tried to remove the Source that is holding the file before we overwrite but it still doesnt work. The 'Clear()' function doesnt free up the file either.
We didnt load the file into the Source of the MediaPlayer on Page_Load and we were able to successfully overwrite the file. So rights are fine, it seems the MediaPlayer is locking onto the file even after we remove it from the Source.
Our clients can only save 1 file out, which they can overwrite with a new one. This works fine as long as the MediaPlayer doesnt have it added to its Source. We need it to be loaded on Page_Load and replaced at will via the RadAsyncUpload and 'swapped' out with the current Source(0).
Can you tell us how to 'free' up the file from the MediaPlayer so it can be overwritten and not locked?
Thanks!
6 Answers, 1 is accepted
0
Hi RSI,
I am sending a sample web site to demonstrate how you can achieve the requested functionality. Please run the attached application and let me know if it helps you.
Regards,
Eyup
Telerik
I am sending a sample web site to demonstrate how you can achieve the requested functionality. Please run the attached application and let me know if it helps you.
Regards,
Eyup
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
SDI
Top achievements
Rank 1
answered on 23 Aug 2014, 08:47 PM
I tried to implement what you are doing with dynamically loading the MediaPlayer, but same error occurs.
Now on Postback the Placeholder doesnt hang on to its controls and its lost. So we create a new MediaPlayer every time the Upload button is clicked. A file is selected and then attempt to overwrite the same file, but the '...being used...' error occurs still, its still being locked up by the first dynamically controlled MediaPlayer.
Why is it not letting go of the file after postback, or after the Source property is cleared and/or set to empty string. It should be relinquishing control of the file??
Now on Postback the Placeholder doesnt hang on to its controls and its lost. So we create a new MediaPlayer every time the Upload button is clicked. A file is selected and then attempt to overwrite the same file, but the '...being used...' error occurs still, its still being locked up by the first dynamically controlled MediaPlayer.
Why is it not letting go of the file after postback, or after the Source property is cleared and/or set to empty string. It should be relinquishing control of the file??
0
Hi Brian,
Since I'm not familiar with your specific implementation, it is difficult to suggest an accurate solution.
Essentially, if you follow the approach demonstrated in the provided sample in my first reply, there should not be any issues. For changing the source of the media player dynamically, you can also check the following sample:
http://demos.telerik.com/aspnet-ajax/media-player/examples/functionality/mediatypes/defaultcs.aspx
Hope this helps.
Regards,
Eyup
Telerik
Since I'm not familiar with your specific implementation, it is difficult to suggest an accurate solution.
Essentially, if you follow the approach demonstrated in the provided sample in my first reply, there should not be any issues. For changing the source of the media player dynamically, you can also check the following sample:
http://demos.telerik.com/aspnet-ajax/media-player/examples/functionality/mediatypes/defaultcs.aspx
Hope this helps.
Regards,
Eyup
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
SDI
Top achievements
Rank 1
answered on 27 Aug 2014, 01:25 PM
Eyup, let put some more code in here for you. This is definately a problem with the MediaPlayer holding on to the file and it unable to replace the file on the server if the MediaPlayer has it in the Source OR removed from the Source. You gave me an example of just changing out the Source in the MediaPlayer, not one that is reads a MP4 file in and then try to replace that file with a different video. Maybe I didn't explain it correctly, I dont know, but this is an issue, as the MediaPlayer should not be holding on to the file.
ASPX
Server Code
As you can see the video in the 'Videos' folder is loaded into the MediaPlayer on PAGE_LOAD, then the same file is trying to be overwritten by the user and re-loaded into the Player. This is where the error occurs, it doesnt seem to matter if its removed from the Player sources before its overwritten, its '...being used by another process..' by the Player.
Please try out this scenario, this is a problem. Thanks
ASPX
<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" DefaultLoadingPanelID="RadAjaxLoadingPanel1"
EnableAJAX="true">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadButtonUpload">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="Panel1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
<ClientEvents OnResponseEnd="OnResponseEnd" OnRequestStart="OnRequestStart" />
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" ToolTip="Please wait..." Height="50px" Width="50px" Skin="Web20" />
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" />
<asp:Panel runat="server" ID="Panel1" Width="775px" Height="800px">
<
div
style
=
"float:left; margin: 25px;"
>
<
telerik:RadAsyncUpload
runat
=
"server"
ID
=
"RadAsyncUpload1"
MultipleFileSelection
=
"Automatic"
MaxFileInputsCount
=
"1"
InitialFileInputsCount
=
"1"
AutoAddFileInputs
=
"true"
AllowedFileExtensions
=
"mp4"
MaxFileSize
=
"10485760"
Skin
=
"WebBlue"
OnClientValidationFailed
=
"OnClientValidationFailed"
OnClientFilesUploaded
=
"OnClientFilesUploaded"
ToolTip
=
"Select an MP4 video to upload. File size limit 10 MB"
>
<
Localization
Select
=
"Browse..."
/>
</
telerik:RadAsyncUpload
>
</
div
>
<
div
id
=
"divUpload"
style
=
"float: left; width: 100%; display: none;"
>
<
telerik:RadButton
runat
=
"server"
ID
=
"RadButtonUpload"
OnClick
=
"RadButtonUpload_Click"
/>
</
div
>
<
div
style
=
"float:left; margin: 25px;"
>
<
telerik:RadMediaPlayer
ID
=
"RadMediaPlayer1"
runat
=
"server"
AutoPlay
=
"false"
MimeType
=
"video/mp4"
Height
=
"360px"
Width
=
"640px"
/>
</
div
>
</asp:Panel>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
function OnClientFilesUploaded(sender, args) {
var myRadButtonUpload = $find('<%=RadButtonUpload.ClientID%>');
//alert("OnClientFilesUploaded");
myRadButtonUpload.click();
}
function OnClientValidationFailed(sender, args) {
var fileExtention = args.get_fileName().substring(args.get_fileName().lastIndexOf('.') + 1, args.get_fileName().length);
//if (args.get_fileName().lastIndexOf('.') != -1) {//this checks if the extension is correct
// if (sender.get_allowedFileExtensions().toUpperCase().indexOf(fileExtention.toUpperCase()) == -1) {
// radalert('A file type of mp4 is only allowed.', 380, 150, 'Wrong File Type');
// }
// else {
// radalert('A file max size of 5MB is allowed.', 330, 150, 'Wrong File Size');
// }
//}
//else {
// alert("not correct extension!");
//}
// delete the uploaded file
sender._updateCancelButton(args.get_row());
$telerik.$(".ruRemove", args.get_row()).click();
}
function OnResponseEnd(sender, eventArgs) {
//alert('Response end initiated by: ' + eventArgs.get_eventTarget());
document.body.style.cursor = "default";
}
function OnRequestStart(sender, eventArgs) {
document.body.style.cursor = "wait";
}
</script>
</telerik:RadScriptBlock>
Server Code
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Me.IsPostBack Then Return
Dim myRadMediaPlayer As RadMediaPlayer = Me.GetNewMediaPlayer()
Dim myMediaPlayerSource As New MediaPlayerSource()
myMediaPlayerSource.Path = "~/videos/test.mp4"
If IO.File.Exists(Server.MapPath(myMediaPlayerSource.Path)) Then
myRadMediaPlayer.Sources.Add(myMediaPlayerSource)
End If
End Sub
Protected Sub RadButtonUpload_Click(sender As Object, e As EventArgs)
For Each myUploadedFile As UploadedFile In Me.RadAsyncUpload1.UploadedFiles
Dim myRadMediaPlayer As RadMediaPlayer = Me.RadMediaPlayer1
Dim myMediaPlayerSource As New MediaPlayerSource()
Dim mySaveLocation As String = "~/videos/test.mp4"
' clear out the media player source
myRadMediaPlayer.Sources.Clear()
myRadMediaPlayer.Source = String.Empty
'Me.Page.ClientScript.RegisterStartupScript(Page.GetType(), "SetTime", String.Format("setTimeout(function(){{ $find('{0}').set_value(0);}}, 100)", myRadMediaPlayer.ClientID + "_Toolbar_ProgressRail"), True)
'Me.Page.ClientScript.RegisterStartupScript(Page.GetType(), "SetTime", String.Format("setTimeout(function(){{ $find('{0}').seekTo(0);}}, 200)", myRadMediaPlayer.ClientID), True)
' save the file out
myUploadedFile.SaveAs(Server.MapPath(mySaveLocation), True)
' load it into the mediaplayersource
myMediaPlayerSource.Path = mySaveLocation
If IO.File.Exists(Server.MapPath(myMediaPlayerSource.Path)) Then
myRadMediaPlayer.Sources.Add(myMediaPlayerSource)
End If
Next
End Sub
As you can see the video in the 'Videos' folder is loaded into the MediaPlayer on PAGE_LOAD, then the same file is trying to be overwritten by the user and re-loaded into the Player. This is where the error occurs, it doesnt seem to matter if its removed from the Player sources before its overwritten, its '...being used by another process..' by the Player.
Please try out this scenario, this is a problem. Thanks
0
SDI
Top achievements
Rank 1
answered on 27 Aug 2014, 01:27 PM
Eyup, let put some more code in here for you. This is definately a problem with the MediaPlayer holding on to the file and it unable to replace the file on the server if the MediaPlayer has it in the Source OR removed from the Source. You gave me an example of just changing out the Source in the MediaPlayer, not one that is reads a MP4 file in and then try to replace that file with a different video. Maybe I didn't explain it correctly, I dont know, but this is an issue, as the MediaPlayer should not be holding on to the file.
ASPX
SERVER SIDE
As you can see the video in the 'Videos' folder is loaded into the MediaPlayer on PAGE_LOAD, then the same file is trying to be overwritten by the user and re-loaded into the Player. This is where the error occurs, it doesnt seem to matter if its removed from the Player sources before its overwritten, its '...being used by another process..' by the Player.
Please try out this scenario, this is a problem. Thanks
ASPX
<
telerik:RadAjaxManager
runat
=
"server"
ID
=
"RadAjaxManager1"
DefaultLoadingPanelID
=
"RadAjaxLoadingPanel1"
EnableAJAX
=
"true"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadButtonUpload"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"Panel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
<
ClientEvents
OnResponseEnd
=
"OnResponseEnd"
OnRequestStart
=
"OnRequestStart"
/>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
runat
=
"server"
ID
=
"RadAjaxLoadingPanel1"
ToolTip
=
"Please wait..."
Height
=
"50px"
Width
=
"50px"
Skin
=
"Web20"
/>
<
telerik:RadWindowManager
ID
=
"RadWindowManager1"
runat
=
"server"
/>
<
asp:Panel
runat
=
"server"
ID
=
"Panel1"
Width
=
"775px"
Height
=
"800px"
>
<
div
style
=
"float:left; margin: 25px;"
>
<
telerik:RadAsyncUpload
runat
=
"server"
ID
=
"RadAsyncUpload1"
MultipleFileSelection
=
"Automatic"
MaxFileInputsCount
=
"1"
InitialFileInputsCount
=
"1"
AutoAddFileInputs
=
"true"
AllowedFileExtensions
=
"mp4"
MaxFileSize
=
"10485760"
Skin
=
"WebBlue"
OnClientValidationFailed
=
"OnClientValidationFailed"
OnClientFilesUploaded
=
"OnClientFilesUploaded"
ToolTip
=
"Select an MP4 video to upload. File size limit 10 MB"
>
<
Localization
Select
=
"Browse..."
/>
</
telerik:RadAsyncUpload
>
</
div
>
<
div
id
=
"divUpload"
style
=
"float: left; width: 100%; display: none;"
>
<
telerik:RadButton
runat
=
"server"
ID
=
"RadButtonUpload"
OnClick
=
"RadButtonUpload_Click"
/>
</
div
>
<
div
style
=
"float:left; margin: 25px;"
>
<
telerik:RadMediaPlayer
ID
=
"RadMediaPlayer1"
runat
=
"server"
AutoPlay
=
"false"
MimeType
=
"video/mp4"
Height
=
"360px"
Width
=
"640px"
/>
</
div
>
</
asp:Panel
>
<
telerik:RadScriptBlock
ID
=
"RadScriptBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function OnClientFilesUploaded(sender, args) {
var myRadButtonUpload = $find('<%=RadButtonUpload.ClientID%>');
//alert("OnClientFilesUploaded");
myRadButtonUpload.click();
}
function OnClientValidationFailed(sender, args) {
var fileExtention = args.get_fileName().substring(args.get_fileName().lastIndexOf('.') + 1, args.get_fileName().length);
//if (args.get_fileName().lastIndexOf('.') != -1) {//this checks if the extension is correct
// if (sender.get_allowedFileExtensions().toUpperCase().indexOf(fileExtention.toUpperCase()) == -1) {
// radalert('A file type of mp4 is only allowed.', 380, 150, 'Wrong File Type');
// }
// else {
// radalert('A file max size of 5MB is allowed.', 330, 150, 'Wrong File Size');
// }
//}
//else {
// alert("not correct extension!");
//}
// delete the uploaded file
sender._updateCancelButton(args.get_row());
$telerik.$(".ruRemove", args.get_row()).click();
}
function OnResponseEnd(sender, eventArgs) {
//alert('Response end initiated by: ' + eventArgs.get_eventTarget());
document.body.style.cursor = "default";
}
function OnRequestStart(sender, eventArgs) {
document.body.style.cursor = "wait";
}
</
script
>
</
telerik:RadScriptBlock
>
SERVER SIDE
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Me.IsPostBack Then Return
Dim myRadMediaPlayer As RadMediaPlayer = Me.GetNewMediaPlayer()
Dim myMediaPlayerSource As New MediaPlayerSource()
myMediaPlayerSource.Path = "~/videos/test.mp4"
If IO.File.Exists(Server.MapPath(myMediaPlayerSource.Path)) Then
myRadMediaPlayer.Sources.Add(myMediaPlayerSource)
End If
End Sub
Protected Sub RadButtonUpload_Click(sender As Object, e As EventArgs)
For Each myUploadedFile As UploadedFile In Me.RadAsyncUpload1.UploadedFiles
Dim myRadMediaPlayer As RadMediaPlayer = Me.RadMediaPlayer1
Dim myMediaPlayerSource As New MediaPlayerSource()
Dim mySaveLocation As String = "~/videos/test.mp4"
' clear out the media player source
myRadMediaPlayer.Sources.Clear()
myRadMediaPlayer.Source = String.Empty
'Me.Page.ClientScript.RegisterStartupScript(Page.GetType(), "SetTime", String.Format("setTimeout(function(){{ $find('{0}').set_value(0);}}, 100)", myRadMediaPlayer.ClientID + "_Toolbar_ProgressRail"), True)
'Me.Page.ClientScript.RegisterStartupScript(Page.GetType(), "SetTime", String.Format("setTimeout(function(){{ $find('{0}').seekTo(0);}}, 200)", myRadMediaPlayer.ClientID), True)
' save the file out
myUploadedFile.SaveAs(Server.MapPath(mySaveLocation), True)
' load it into the mediaplayersource
myMediaPlayerSource.Path = mySaveLocation
If IO.File.Exists(Server.MapPath(myMediaPlayerSource.Path)) Then
myRadMediaPlayer.Sources.Add(myMediaPlayerSource)
End If
Next
End Sub
As you can see the video in the 'Videos' folder is loaded into the MediaPlayer on PAGE_LOAD, then the same file is trying to be overwritten by the user and re-loaded into the Player. This is where the error occurs, it doesnt seem to matter if its removed from the Player sources before its overwritten, its '...being used by another process..' by the Player.
Please try out this scenario, this is a problem. Thanks
0
Hi,
Note that the Page_Load event may be too late to allow handling media player sources. You need to transfer your logic somehow to Page_Init:
http://demos.telerik.com/aspnet-ajax/media-player/examples/functionality/mediatypes/defaultcs.aspx
If the issue is still present after the suggested modification, please open a formal support ticket to send us a very basic runnable web site demonstrating the problematic behavior. Thus, we will be able to further analyze and debug the project locally and try to determine the cause of the issue.
Regards,
Eyup
Telerik
Note that the Page_Load event may be too late to allow handling media player sources. You need to transfer your logic somehow to Page_Init:
http://demos.telerik.com/aspnet-ajax/media-player/examples/functionality/mediatypes/defaultcs.aspx
If the issue is still present after the suggested modification, please open a formal support ticket to send us a very basic runnable web site demonstrating the problematic behavior. Thus, we will be able to further analyze and debug the project locally and try to determine the cause of the issue.
Regards,
Eyup
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.