I think you need to look at what drives toddlers. Like you mentioned toddlers love reactions. So yelling and holding his arms down is only giving more of a reaction.
Walking away is a very good response. It should be clear that if he hits you he loses his playmate. However my experience with my kids is a bit more nuanced. I've got some special need kids and this works for them. I hope this works for your situation too
- When starting to play make it clear what you are going to play.
For example, if you are playing with some toy cars then tell them
when starting "now we're playing with toy cars, once we're finished
mommy is going to make dinner".
- Explain/reiterate the rules of the game. "Car's are not allowed to
fly through the room and no hitting anyone". You might need to do
this every time.
- Think about what game you want to play. If your goal is just to
entertain them, make sure you play their game. Sometimes my kids
will rearrange cars by color (or something different that you might
not expect). That's fine. Just join them in their game. At times I
also use games to teach them something. (Only of my kids are very
slow at using language, so then I'll only 'understand' what they
want if they actually speak the words). That also means that I
expect some amount of frustration when I do that. It also means that
I can move away if my daughter tries to hurt me out of frustration
- Don't leave them 'hanging' after playing a game. If after playing
for 30 minutes you just say "ok, now go play on your own" then they
probably will be very frustrated (they had a good time playing
with you and now you stop). It will be much easier if you nudge them
towards a different activity. For example, tell them "ok, now you can
draw a picture for daddy, and once you're finished you get a snack".
This way you reward them for playing nice and slowly also get them
to do something on their own. Maybe my kids were slightly older when
I got them to draw before the snack so maybe just rewarding them for
playing nice would be easier to start out with.
It might not be completely 'by the books' but if you do stop
playing because they hit you make sure they understand why. I've got
a loud voice and if I stop I make sure I play (ok, sometimes not
play but that's dangerous) being angry. It shouldn't be that they
get stuck in their tantrum, it's me being angry and making it very
clear that if they hit me that I'm angry and won't play.
Small update: The reason raising your voice doesn't work is that it by itself won't convince them to stop their behavior. At that age you can't expect reasoning like "I don't want to make mommy mad". Also it's very temping to overreact (i'm guilty of that myself). If you are actually angry and if you say "no TV for a week" then it will undermine you if you do have to give in later. The only thing you should use it for to communicate that you stop playing, and why you stop playing.
And like you mentioned, consistency. For my kids these kind of changes can take 6 months or so before they really 'master' the things I want to teach them. (and even with the oldest after doing this for +- 4 years we're not completly tandrum free, although it is less than once a month. However he doesn't hit anyone anymore during his tandrums).