Updated:

1. Play a disc song (Java)

/playsound minecraft:music_disc.pigstep record @a ~ ~ ~ 1 1

The record category follows the Jukebox/Note Blocks volume slider. Players far from the position will not hear it.

2. Everyone hears it (Java)

/execute as @a at @s run playsound minecraft:music_disc.pigstep record @s ~ ~ ~ 1 1

The sound stays where it started, so replay it now and then in games with lots of travel.

3. Common sound names

SongJavaBedrock
Pigstepmusic_disc.pigsteprecord.pigstep
othersidemusic_disc.othersiderecord.otherside
catmusic_disc.catrecord.cat
Relicmusic_disc.relicrecord.relic
Creative musicmusic.creative-
/playsound record.pigstep @a

4. Stop the music

/stopsound @a record

Use /stopsound @a music for background music. On Bedrock stop by name, such as /stopsound @a record.pigstep.

5. Give a music disc

/give @p music_disc_pigstep

The item ID uses underscores, the sound ID a dot. See the playsound command.

6. Play once when players enter an area (Java)

/execute as @a[tag=!heard,x=0,y=60,z=0,dx=10,dy=10,dz=10] at @s run playsound minecraft:music_disc.otherside record @s ~ ~ ~ 1 1
/tag @a[x=0,y=60,z=0,dx=10,dy=10,dz=10] add heard

The heard tag stops the song repeating for the same player. See the tag command.

Troubleshooting

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.