How do I play a music file from a network server

GuyBooth

Active Member
Licensed User
Longtime User
I have built a music player that plays mp3s from local internal memory or an external microsd card. Loading it is simply a matter of loading the directory and filename into the standard mediaplayer and playing it.

How can I play files from my local network servers instead of the local memory? So far my attempts to "find" the files have not worked. I have notused the network libraries, but the examples I have seen so far have been related to setting up a "job" - but I don't see a way to refer to that when using the mediaplayer.

I have also read references to streaming from a www address, but I am not dealing with a website.

Any help to get me pointed in the right direction would be appreciated .
 

GuyBooth

Active Member
Licensed User
Longtime User
You can use SMB library to download the file and then play it. Another option is to use MediaPlayerStream. However it will only work with supported protocols.

Using smb I can "see" the files I want to play (I tested that htis morning) and can probably download and play them.

When I try to use MediaPlayerStream I cannot get it to recognize that the files exist.

B4X:
' Note MPS and SMB1 are declared as MediaPlayerStream and SMB in Globals as required
Sub Test_Click
Dim url, sPath, sPath2, sFile As String
Dim UserName, Password, Domain As String
UserName = "*********"
Password = "*******"
Domain = "********"

SMB1.Initialize("SMB1")
SMB1.SetCredentials(UserName,Password,Domain)

sPath = "smb://TBCI-01-NAS1/NA_Media/Music/StreamTest/"
sPath2 = "file://TBCI-01-NAS1/NA_Media/Music/StreamTest/"
sFile = "test1.mp3"
url = File.Combine(sPath,sFile)

SMB1.ListFiles(sPath,sFile)
MPS.Initialize("MPS")

[B]Log("File Exists: " & File.Exists(sPath,sFile))
Log("File Exists: " & File.Exists(sPath2,sFile))[/B]
MPS.Load(url)

End Sub

Sub SMB1_ListCompleted(Url As String, Success As Boolean, Entries() As SMBFile)
    If Not(Success) Then
      Log(LastException)
   Else
      For i = 0 To Entries.Length - 1
         Log("*****************")
         Log(Entries(i).Name)
         Log(Entries(i).Directory)
         Log(DateTime.Date(Entries(i).LastModified))
         Log(Entries(i).Parent) 
         Log(Entries(i).Size)
      Next
   End If
End Sub

Sub MPS_StreamReady
  Log ("Stream Ready")
  MPS.Play
End Sub

Sub mps_StreamError (ErrorCode As String, ExtraData As Int)
    Log("Error: " & ErrorCode & ", " & ExtraData)
    ToastMessageShow("Error: " & ErrorCode & ", " & ExtraData, True)
End Sub

Both the "File.Exists" statements return False - so the MPS.Load statement fails. I can't see any way to combine the smb with the stream statements.

Is there a way around this? (In VB6 I was using the StreamDirector object.)
 
Upvote 0
Top