MediaPlayer Stream - to Stop it

b4AMarkO

Member
Licensed User
Longtime User
Ok first off I know how to stop the stream ...

mp.Stop gets it done except under this circumstance

First let me show you the code and then what the problem is

B4X:
Sub tbScan_CheckedChange(Checked As Boolean)
     
    If Checked = True Then
       mp.Initialize("mp")
      mp.Load("http://relay.radioreference.com:80/264858664")
      Activity.Title = "Loading Media"
    Else
      mp.Stop 
    End If
      
End Sub
Above Code gets it done ... starts the stream and if I need to stop it I just hit the Toggle Button again and it stops it
So whats the problem then right?

Well it starts with the next code

B4X:
Sub btnLiveCalls_Click
        RemoveViews
     Activity.LoadLayout("NewLayout")
   
   Download
    
End Sub

When I load the new layout it goes just fine newlayout works great
Also .... the Stream is still playing and I want it to
but when I hit the next block of code to return to original layout called (imgLayout)

This is where the problem is

B4X:
Sub btnReturn_Click
    
     RemoveViews
     Activity.LoadLayout("imgLayout")
     If db.Exist(db.FilePath_ & db.FileName_) Then
      db.ResetPointers
      db.GetRecord
   Else
      ' do nothing
   End If
   
   
 End Sub


When I return the Main layout is restored thMediaStream is still playing as I wish it to
BUT ....... The Toggle Button is restored too but is in off position

so when I click on it it doesnt stop the MediaStream it starts a new one
or does nothing
but doesnt stop it

SO what I think I need is .... in tbScan_CheckedChange event I think what I need to do is rewrite that code so that that it checks to see if a stream is playing maybe?

If MediaStream Exist then

mp.stop


Or something what do I do guys?
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Without knowing more about the apps design and what it's doing it is difficult to give you a definitive answer. You could Run the media player in a service and use different activities for the different layouts or you could load the layouts into separate panels and not remove them but simply hide them (panel.visible=false), then when you recall the panel (layout) it will be using the same views and in the same state.

The bottom line is why do you have to remove the views in the first place?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Not if you load the layout into a panel, you can have multiple layouts loaded and manage them by displaying (or not) then panels into which they are loaded.

Or as the other option above, use multiple activities.

B4X:
pnl.LoadLayout("layout.bal")
 
Last edited:
Upvote 0

b4AMarkO

Member
Licensed User
Longtime User
Not if you load the layout into a panel, you can have multiple layouts loaded and manage them by displaying (or not) then panels into which they are loaded.

B4X:
pnl.LoadLayout("layout.bal")

So .... If I understand you ... instead of loading layouts into activity

I have two Panels

One with imgLayout Loaded into it and one with NewLayout loaded into it


So pnl1.Visible = True & pnl2.Visible = False

OR
pnl1.Visible = False & pnl2.Visible = True

also I would load both panels at Activity_Create Right?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yes, that would do it.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
There are many discussions about Panels Vs Activities on the Forum, just search for 'multiple activities' and you'll find them. It may help you decide which way is best for your app.
 
Upvote 0
Top