The idea sounds like trouble. You have to assume that it's quite possible that kids larger than your child may attempt to hang on the swing. Perhaps even an adult! This would stress the 2x4 rather quickly. Even if you could be guaranteed that only the weight of a child would be set against the board, the board will shrink and expand, thus degrade, over time.
There is one idea but w/o knowing the thickness of the 2 branches on the 2 trees or their 'angle' (ie., are you thinking of attaching to the trunk or an actual branch), you have to give this some thought. The Home Centers have different types of galvanized or iron piping that's 8 feet in length. Perhaps you need 2 for added strength. Using pipe, you've eliminated the shrinking and expanding qualities of your 'board'. The next thing is how are you going to keep it from sliding left to right?
Assuming there are 2 branches (not trunks) that you'll be using as 'ends', drill a 1/4" hole all the way through the piping on BOTH ends. Then, slip threaded, galvanized bolts into them such that they 'protrude' from your pre-drilled holes. Using lock-washers, screw them down tight. Now, if the pole was to slide, you'd have bolts to prevent the bar/pipe from sliding off a branch. Now, you need to see what you can do to do 2 more things: 1) prevent it from rolling, and 2) keep it in place. You might want to figure the use of WHERE TO PRE-DRILL the holes as part of the equation to solve the rolling, slipping, and sliding of the pipe.
Other than that, either build or buy a swing set if kids will be joining the household for a few years to come. My best to ya and hope this is safe and that it helps.