Sub DownloadedMp3File
ProgressBarDownloading.Indeterminate = True
ProgressBarDownloading.Visible = True
HttpUtils.Download("Job1", mp3Url)
End Sub
Sub JobDone(Job As String)
Select Job
Case "Job1"
If HttpUtils.IsSuccess(mp3Url) Then
Dim mp3 As InputStream
mp3 = HttpUtils.GetInputStream(mp3Url)
File.Copy2(mp3,File.OpenOutput(File.DirInternal,"077.mp3",False))
ProgressBarDownloading.Visible = False
ToggleButtonPlayPause.Checked = True
ToggleButtonPlayPause.Enabled = True
blnCurrentPauseCheckedState = True
blnCurrentPauseEnabledState = True
mpTheMediaPlayer.Release
mpTheMediaPlayer.Initialize2("SurahAlMorsalat")
mpTheMediaPlayer.Load(File.DirInternal, "077.mp3")
mpTheMediaPlayer.Play
End If
End Select
End Sub
Dim out As OutputStream
out = File.OpenOutput(File.DirInternal,"077.mp3",False)
File.Copy2(mp3, out)
out.Close
Sub JobDone(Job As String)
Select Job
Case "Job1"
'Dim p As Phone
'Dim sb As StringBuilder
'sb.Initialize
'p.Shell("df", Null, sb, Null)
'Msgbox(sb.ToString, "Free space:")
If HttpUtils.IsSuccess(mp3Url) Then
Dim mp3 As InputStream
mp3 = HttpUtils.GetInputStream(mp3Url)
Dim out As OutputStream
out = File.OpenOutput(File.DirInternal,"077.mp3",False)
File.Copy2(mp3, out)
out.Close
ProgressBarDownloading.Visible = False
ToggleButtonPlayPause.Checked = True
ToggleButtonPlayPause.Enabled = True
blnCurrentPauseCheckedState = True
blnCurrentPauseEnabledState = True
mpTheMediaPlayer.Release
mpTheMediaPlayer.Initialize2("SurahAlMosalat")
mpTheMediaPlayer.Load(File.DirInternal, "077.mp3")
mpTheMediaPlayer.Play
End If
End Select
The output stream is not closed automatically by File.Copy2. You should change your code to:
B4X:Dim out As OutputStream out = File.OpenOutput(File.DirInternal,"077.mp3",False) File.Copy2(mp3, out) out.Close
It is not possible to write anything to the assets folder.
2204936 out of 2390502
2204936 out of 2390502
2204936 out of 2390502
2275888 out of 2390502
2356976 out of 2390502
2362768 out of 2390502
2362768 out of 2390502
2390502 out of 2390502
Success!
main_response_streamfinish (B4A line: 370)
mpTheMediaPlayer.Load(File.DirInternal, "001.mp3")
java.io.IOException: Prepare failed.: status=0x1
at android.media.MediaPlayer.prepare(Native Method)
at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:79)
at quran.repeater.main._response_streamfinish(main.java:928)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
at anywheresoftware.b4a.BA$1.run(BA.java:218)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3647)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
java.io.IOException: Prepare failed.: status=0x1
What device are you using, and what are the paths of DirInternal and DirRootExternal?
It looks to me that the MediaPlayer needs to re-scan media after the download. (May be just a hunch)
TotalBytes is returned in the Http header response from the server.
What you have shown in the logs, is the 'progress' of the download, not multiple files being downloaded.
Dim blnFolderMade As Boolean
File.MakeDir(File.DirInternal, "MyFiles")
blnFolderMade = File.Exists(File.DirInternal,"MyFiles")
Msgbox(blnFolderMade, "Folder Made")
I thought so too. Try using MkDir.
Also I am wondering how this will work with the mediaplayer.
Can the mediaplayer object access media from DirInternal of an app?
but when I use the file manager to see it I can't find it in /data/data/myapp/files
In fact the /data folder is empty without any folder in it.
Am I looking at the right place? Could this be a permissions thing that needs to be set? I hope B4A has a way to set the permissions so this fold can be seen.
No attachment?
Your submission could not be processed because a security token was missing or mismatched.
If this occurred unexpectedly, please inform the administrator and describe the action you performed before you received this error.
This is an internal permission issue. For now you will only be able to use File.DirAssets (for packaged sound files) or the sd card. I will investigate it for the next update.
No. It will not work without an SD card.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?