Our opinions and ideas are shaped by what our friends said and what we read or watched on mass media. In this paper, we propose a concise and analyzable model to study the effects of mass media modeled as an applied external field, and social networks on public opinions based on the multi-state voter model, and a tuned parameter can control the relative intensity of the effects of mass media and social networks. We consider a generalized scenario where there exist committed or stubborn agents in the networks whose opinions are not affected by their friends or mass media. We find that the fraction of each opinion will converge to a value which only relates to the fractions and degrees of stubborn agents, and the relative intensity between media and network effects. The final agents with media opinion, except the stubborn agents, also include the increment produced by the internal impact of social networks and that caused by the external impact of media. Interestingly the second increment is composed of two parts, one is from the media effect when there are no interactions between agents and the other is from the influence of media on agent opinions caused by social network structure. That is the interactions among agents within social networks can amplify media influence. Finally we also discuss several extensions to the dynamics model which consider more realistic scenarios.