Normally when you have a probability measure $\nu$ on some measure space $(\mathcal{S},\mathcal{F},\nu)$ and you write "let $X$ be a random variable with $X\sim \nu$", then it just means that $X$ is a measurable mapping from some probability space $(\Omega,\mathcal{H},P)$ such that $X(P)=\nu$. In other words $\nu$ is the distribution of $X$.
In your case you are given a probability measure $\mu$ on the product space $\mathcal{S}\times \mathbb{R}$. When we now say that $(A,B) \sim \mu$, we simply mean that $A,B$ are random variables/elements defined on some common probability space $(\Omega,\mathcal{H},P)$ such that the pushforward measure $(A,B)(P)=\mu$, that is $\mu$ is the simultaneous distribution of $A$ and $B$. Here $(A,B)(P)$ is the pushforward measure of $P$ with the bundle map $\omega\mapsto(A(\omega),B(\omega))\in\mathcal{S}\times\mathbb{R}$. Constructing the bundle $(A,B)$ like this, will yield that the marginal distributions are given by $A\sim \pi_1(\mu)$ and $B \sim \pi_2(\mu)$
Similarly we can arrive at the following representation of the expectation of $B$:
\begin{align*}
E(B) &= \int_{\Omega} B(\omega) \, dP(\omega) \\
&= \int_{\Omega} \pi_2(A(\omega),B(\omega)) \, dP(\omega)\\
&=\int_{\mathcal{S}\times \mathbb{R}} \pi_2(a,b) \, d(A,B)(P)(a,b)\\
&= \int_{\mathcal{S}\times \mathbb{R}} \pi_2(a,b) \, d\mu(a,b) \\
&= \int_{ \mathbb{R}} b \, d \pi_2(\mu)(b)
\end{align*}
where we used the abstract change of variable theorem, and that $\pi_2$ is the coordinate projection onto the second coordinate, that is $\pi_2 :\mathcal{S}\times \mathbb{R}\to \mathbb{R}$ given by $\pi_2(s,x) =x$ for any $(s,x)\in\mathcal{S}\times \mathbb{R}$.
One way to construct $A$ and $B$ rigorously is to let the common probability space be given by $(\mathcal{S}\times \mathbb{R}, \mathcal{B}(\mathcal(S))\otimes \mathcal{B}(\mathbb{R}),\mu)$ and now define the random variables/elements as $A=\pi_1$ and $B=\pi_2$.