Android Question play .pls file with mediaplayerstream

dualznz

Member
Licensed User
Longtime User
hi all a quick question
im writing a app that has a shoutcast server, so i have inherited the listen.pls from the stream url but nothing plays in mediaplayerstream

i even put the listen.pls into the files folder and used mediaplayer but it just crashes the application?

any help on how i can stream the .pls file on the app

cheers
 

DonManfred

Expert
Licensed User
Longtime User
als pls is not a streaming media... It is a textfile which holds "links" to streaming media...
Load the file and extract the stream-url´s from it and then play the stream
[playlist]
NumberOfEntries=3

File1=http://streamexample.com:80
Title1=My Favorite Online Radio
Length1=-1

File2=http://example.com/song.mp3
Title2=Remote MP3
Length2=286

File3=D:\Eigene Musik\album.flac
Title3=Local album
Length3=3487

Version=2
 
Upvote 0

dualznz

Member
Licensed User
Longtime User
hi thanks for the reply i opened up the file in notepad++
and this was in it
B4X:
[playlist]
NumberOfEntries=1
File1=http://radio.webradiovip.be:9500/

so in my project i added

B4X:
mp.Load("http://radio.webradiovip.be:9500")
mp.Play

i dont hear anything in return, in the log i have a entry called start plying to ensure that its starting the sub and it is
 
Upvote 0

dualznz

Member
Licensed User
Longtime User
hi earl thanks for the reply, i have added the mediaplayerstream into the application from the audio libary with no luck nothing is being played
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim httpC As HttpClient
    Dim httpD As HttpClient
   
    Dim mp As MediaPlayerStream

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("player")
   
    ' Load layout Interface
    layoutui
   
    ' initiate the http client
    httpC.Initialize("httpC")
   
    ' initiate timer
    startpacket.Initialize("startpacket", 2000)
    startpacket.Enabled = True
   
    ' initiate the player
    mp.Initialize(mp)
  ' Audio.Initialize("Audio", 44100, False, 16, Audio.VOLUME_MUSIC)
   
    mp.Load("http://radio.webradiovip.be:9500/")
        mp_StreamReady

End Sub

Sub mp_StreamReady
    Log("starts playing")
    mp.Play
End Sub

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

Sub mp_StreamBuffer(Percentage As Int)
    Log(Percentage)
End Sub

any help on getting it to play?
cheers
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
You have to change this line:

From:
B4X:
mp.Initialize(mp)
To:
B4X:
mp.Initialize("mp") '<-- In quotes

Also, remove the mp_StreamReady even after mp.Load, that event will trigger when the media is ready to be played.
 
Upvote 0

dualznz

Member
Licensed User
Longtime User
thanks for your reply, i have changed the load information to the ip and no playback as of yet
cheers
 
Upvote 0

dualznz

Member
Licensed User
Longtime User
hrmmm this is the complete activity code

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim httpC As HttpClient
    Dim httpD As HttpClient
   
    Dim mp As MediaPlayerStream
    Dim Audio As AudioStreamer

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim sv As ScrollView
    Dim fontface As Typeface
   
    Dim background As Panel
    Dim statustop As Panel
   
    ' routine events
    Dim startpacket As Timer
   
    ' statustop events
    Dim statustitle As Label
    Dim statusvalue As Label
   
    ' status images
    Dim statusonline As ImageView
    Dim statusoffline As ImageView
    Dim onlineimage As Bitmap
    Dim onlineimage_dull As Bitmap
    Dim offlineimage As Bitmap
    Dim offlineimage_dull As Bitmap
   
    ' player cover
    Dim plr_image As Panel
    Dim playerimage As ImageView
    Dim imageplayer As Bitmap
   
    ' main player controls
    Dim player_main As Panel
    Dim lblPosition As Label
   
    ' feed stats
    Dim player_feeds As Panel
    Dim feed_title As Label
    Dim feed_main_title As Label
    Dim listeners As Label
    Dim peaklisteners As Label
    Dim genre As Label
    Dim url As Label
    Dim track As Label
   

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("player")
   
    ' Load layout Interface
    layoutui
   
    ' initiate the http client
    httpC.Initialize("httpC")
   
    ' initiate timer
    startpacket.Initialize("startpacket", 2000)
    startpacket.Enabled = True
   
    ' initiate the player
    mp.Initialize("mp")
  ' Audio.Initialize("Audio", 44100, False, 16, Audio.VOLUME_MUSIC)
    mp.Load("http://46.18.33.24:9000")
End Sub

#Region Layout UI Code

Sub layoutui
    ' design permaeters for the activity
    sv.Initialize(100%y)
    Activity.AddView(sv, 0, 0, 100%x, 100%y)
   
    ' add custom font package into activity
    fontface = Typeface.LoadFromAssets("playtime-webfont.TTF")
   
    background.Initialize("background")
    sv.Panel.AddView(background, 0, 0, 100%x, 100%y)
    background.Color = Colors.RGB(50, 50, 47)
   
    statustop.Initialize("statustop")
    sv.Panel.AddView(statustop, 74%x, 0, 30%x, 20dip)
    'statustop.Color = Colors.Red
   
    statustitle.Initialize("statustitle")
    statustop.AddView(statustitle, 0, 0, 45dip, 20dip)
    statustitle.Text = "status:"
    statustitle.Typeface = fontface
   
    onlineimage.Initialize(File.DirAssets, "online.png")
    onlineimage_dull.Initialize(File.DirAssets, "online_dull.png")
    statusonline.Initialize("statusonline")
    statustop.AddView(statusonline, 45dip, 3dip, 16dip, 16dip)
    statusonline.Bitmap = onlineimage_dull
   
    offlineimage.Initialize(File.DirAssets, "offline.png")
    offlineimage_dull.Initialize(File.DirAssets, "offline_dull.png")
    statusoffline.Initialize("statusoffline")
    statustop.AddView(statusoffline, 65dip, 3dip, 16dip, 16dip)
    statusoffline.Bitmap = offlineimage_dull
   
    plr_image.Initialize("plr_image")
    sv.Panel.AddView(plr_image, 0, 30dip, 200dip, 200dip)
    plr_image.Left = (100%x - 200dip) / 2
   
    imageplayer.Initialize(File.DirAssets, "player_image.png")
    playerimage.Initialize("playerimage")
    plr_image.AddView(playerimage, 0, 0, 200dip, 200dip)
    playerimage.Bitmap = imageplayer
   
    ' title
    feed_main_title.Initialize("feed_main_title")
    sv.Panel.AddView(feed_main_title, 0, 235dip, 100%x, 20dip)
    feed_main_title.Typeface = fontface
    feed_main_title.Gravity = Gravity.CENTER_HORIZONTAL
    'feed_main_title.Color = Colors.Blue
    feed_main_title.TextColor = Colors.White
   
    ' player
    player_main.Initialize("player_main")
    sv.Panel.AddView(player_main, 0, 260dip, 100%x, 30dip)
    player_main.Color = Colors.Red
   
    ' player feeds
    player_feeds.Initialize("player_feeds")
    sv.Panel.AddView(player_feeds, 5%x, 350dip, 90%x, 120dip)
    'player_feeds.Color = Colors.Cyan
   
    feed_title.Initialize("feed_title")
    player_feeds.AddView(feed_title, 0, 0, 100%x, 12dip)
    feed_title.TextColor = Colors.RGB(242, 216, 0)
    feed_title.Typeface = fontface
    feed_title.Text = "Server Statistics:"
    feed_title.TextSize = 10
    'feed_title.Color = Colors.DarkGray
   
    listeners.Initialize("listeners")
    player_feeds.AddView(listeners, 0, 16dip, 100%x, 16dip)
    listeners.Typeface = fontface
    'listeners.Color = Colors.Green
    listeners.TextSize = 14
   
    peaklisteners.Initialize("peaklisteners")
    player_feeds.AddView(peaklisteners, 0, 36dip, 100%x, 16dip)
    peaklisteners.Typeface = fontface
    'peaklisteners.Color = Colors.Green
    peaklisteners.TextSize = 14
   
    genre.Initialize("genre")
    player_feeds.AddView(genre, 0, 56dip, 100%x, 16dip)
    genre.Typeface = fontface
    'genre.Color = Colors.Green
    genre.TextSize = 14
   
    url.Initialize("url")
    player_feeds.AddView(url, 0, 76dip, 100%x, 16dip)
    url.Typeface = fontface
    'url.Color = Colors.Green
    url.TextSize = 14
   
    track.Initialize("track")
    player_feeds.AddView(track, 0, 96dip, 100%x, 16dip)
    track.Typeface = fontface
    'track.Color = Colors.Green
    track.TextSize = 14
   
    lblPosition.Initialize("lblPosition")
    sv.Panel.AddView(lblPosition, 80%x, 300dip, 18%x, 20dip)
    lblPosition.Typeface = fontface
    lblPosition.TextColor = Colors.White
    lblPosition.Text = "0:00 (0:00)"
    lblPosition.Gravity = Gravity.RIGHT
   
End Sub

#End Region

Sub startpacket_Tick
    startpacket.Enabled = False
    ' start the request to get the connection state of the remote server
    Dim req As HttpRequest
    req.InitializeGet("http://steve.dualzdesigns.com/vipradio2/example1.php")
    httpC.Execute(req, 1)
End Sub

Sub httpC_ResponseSuccess(Response As HttpResponse, TaskId As Int)
    Try
        Dim result As String
        result = Response.GetString("UTF8")
        ' status
        Dim status As String
        status = result.SubString(result.IndexOf("[status]") + 12)
        status = status.SubString2(0, status.IndexOf("[") - 5) ' go back 5 spaces to stop the gap between data packets
        'Msgbox(status, "") ' debug only
        If status == "1" Then
            statusonline.Bitmap = onlineimage
            statusoffline.Bitmap = offlineimage_dull
        Else
            statusonline.Bitmap = onlineimage_dull
            statusoffline.Bitmap = offlineimage
        End If
        ' end status
       
        ' listeners
        Dim ret_listeners As String
        ret_listeners = result.SubString(result.IndexOf("[listener]") + 13)
        ret_listeners = ret_listeners.SubString2(0, ret_listeners.IndexOf("[") - 5)
        'Msgbox(ret_listeners, "") ' debug only
       
        Dim ret_maxlisteners As String
        ret_maxlisteners = result.SubString(result.IndexOf("[listener_max]") + 18)
        ret_maxlisteners = ret_maxlisteners.SubString2(0, ret_maxlisteners.IndexOf("[") - 5)
        'Msgbox(ret_maxlisteners, "") ' debug only
        listeners.Text = "Connected: " & ret_listeners & " of " & ret_maxlisteners
        ' end listeners
       
        ' peak listeners
        Dim ret_peakcount As String
        ret_peakcount = result.SubString(result.IndexOf("[peak]") + 9)
        ret_peakcount = ret_peakcount.SubString2(0, ret_peakcount.IndexOf("[") - 5)
        'Msgbox(ret_peakcount, "") ' debug only
        peaklisteners.Text = "Peak Listeners: " & ret_peakcount
        ' end peak listeners
       
        ' genre
        Dim ret_genre As String
        ret_genre = result.SubString(result.IndexOf("[genre]") + 10)
        ret_genre = ret_genre.SubString2(0, ret_genre.IndexOf("[") - 5)
        'Msgbox(ret_genre, "") ' debug only
        genre.Text = "Genre: " & ret_genre
        ' end genre
       
        ' url
        Dim ret_url As String
        ret_url = result.SubString(result.IndexOf("[url]") + 8)
        ret_url = ret_url.SubString2(0, ret_url.IndexOf("[") - 5)
        'Msgbox(ret_url, "") ' debug only
        url.Text = "Url: " & ret_url
        ' end url
       
        ' track
        Dim ret_track As String
        ret_track = result.SubString(result.IndexOf("[track]") + 10)
        ret_track = ret_track.SubString2(0, ret_track.IndexOf(")") - 1)
        'Msgbox(ret_track1, "") ' debug only
        track.Text = "Track: " & ret_track
        ' end track
       
        ' title
        Dim ret_title As String
        ret_title = result.SubString(result.IndexOf("[title]") + 10)
        ret_title = ret_title.SubString2(0, ret_title.IndexOf("[") - 5)
        'Msgbox(ret_title, "") ' debug only
        feed_main_title.Text = ret_title
        ' end title
       
        ' start the player (DEBUG ONLY)
        mp_StreamReady
    Catch
   
    End Try
End Sub

Sub mp_StreamReady
    Log("starts playing")
    mp.Play
End Sub

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

Sub mp_StreamBuffer(Percentage As Int)
    Log(Percentage)
End Sub


#Region unused routines

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

#End Region
 
Upvote 0

dualznz

Member
Licensed User
Longtime User
ok never mind its working on the emulator its just not playing on my old rooted anroid cruz tablet, cheers
 
Upvote 0

EddyW

Member
Licensed User
Longtime User
below is a example how i used it but then as a service

B4X:
Sub Process_Globals
    Public Audio As MediaPlayerStream
End Sub

Sub Service_Create
    Audio.Initialize("Audio")
End Sub

Sub Service_Start (StartingIntent As Intent)
End Sub

Sub Service_Destroy
    If Audio.IsPlaying = True Then
        Audio.Stop
        Audio.Release
    End If
End Sub

Sub StartStream(sStream As String)
    If Audio.IsPlaying = True Then
        Audio.Stop
    End If
    Audio.Load(sStream)
End Sub

Sub StopStream()
    If Audio.IsPlaying = True Then
        Audio.Stop
    End If
End Sub

Sub Audio_StreamReady()
    Audio.Play
End Sub

Sub Audio_StreamError (ErrorCode As String, ExtraData As Int)
    Log("Error: " & ErrorCode & ", " & ExtraData)
    ToastMessageShow("Error: " & "Cant find stream!", True)
End Sub
 
Upvote 0

dualznz

Member
Licensed User
Longtime User
hi it appears to be working, now i just have an issue with the counter, (total time played)
im using

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("player")
  
    ' Load layout Interface
    layoutui
  
    ' initiate the http client
    httpC.Initialize("httpC")
  
    ' initiate timer
    startpacket.Initialize("startpacket", 2000)
    startpacket.Enabled = True
  
    If FirstTime Then
        ' initiate the player
        mp.Initialize("mp")
          ' Audio.Initialize("Audio", 44100, False, 16, Audio.VOLUME_MUSIC)
        mp.Load("http://46.18.33.24:9000")
        timer1.Initialize("timer1", 1000)
    End If
End Sub

Sub timer1_Tick
    If mp.IsPlaying Then
        lblPosition.Text = "Position: " & ConvertToTimeFormat(mp) & " (" & ConvertToTimeFormat(mp.Duration) & ")"
    End If
End Sub
 
Upvote 0
Top